Coder Social home page Coder Social logo

pg_hashids's Introduction

pg_hashids, generate short unique ids from integers

Hashids is a small open-source library that generates short, unique, non-sequential ids from numbers. It converts numbers like 347 into strings like “yr8”. You can also decode those ids back. This is useful in bundling several parameters into one or simply using them as short UIDs.

You can use hashids to hide primary keys in your database. I've used the extension on several production databases.

Tested PostgreSQL versions : 9.5.X and 9.6.X (Should work on older versions, just not tested)

It's using hashids.c under the hood. More information about hashids and it's implementations here: hashids.org

Installation

Make sure you have development packages installed for postgres and build tools in general.

$ git clone https://github.com/iCyberon/pg_hashids
$ cd pg_hashids
# Make sure your path includes the bin directory that contains the correct `pg_config`
$ PATH=/path/to/pg/bin:$PATH
$ USE_PGXS=1 make
$ USE_PGXS=1 make install

Then in a psql session issue:

CREATE extension pg_hashids;

Update

Install as usual.

$ git clone https://github.com/iCyberon/pg_hashids
$ cd pg_hashids
# Make sure your path includes the bin directory that contains the correct `pg_config`
$ PATH=/path/to/pg/bin:$PATH
$ USE_PGXS=1 make
$ USE_PGXS=1 make install

Then in a psql session issue:

ALTER EXTENSION pg_hashids UPDATE;

or

DROP EXTENSION pg_hashids;
CREATE EXTENSION pg_hashids;

Check

SELECT default_version, installed_version FROM pg_available_extensions WHERE name = 'pg_hashids';

Tests

$ USE_PGXS=1 make installcheck

Usage

Encoding

Returns a hash using the default alphabet and empty salt.

SELECT id_encode(1001); -- Result: jNl

Returns a hash using the default alphabet and supplied salt.

SELECT id_encode(1234567, 'This is my salt'); -- Result: Pdzxp

Returns a hash using the default alphabet, salt and minimum hash length.

SELECT id_encode(1234567, 'This is my salt', 10); -- Result: PlRPdzxpR7

Returns a hash using the supplied alphabet, salt and minimum hash length.

SELECT id_encode(1234567, 'This is my salt', 10, 'abcdefghijABCDxFGHIJ1234567890'); -- Result: 3GJ956J9B9

Decoding

You can also decode previously generated hashes. Just use the same salt, otherwise you'll get wrong results.

SELECT id_decode('PlRPdzxpR7', 'This is my salt', 10); -- Result: 1234567

Using a custom alphabet

SELECT id_decode('3GJ956J9B9', 'This is my salt', 10, 'abcdefghijABCDxFGHIJ1234567890'); -- Result: 1234567

pg_hashids's People

Contributors

0xflotus avatar dwagin avatar evancarroll avatar fabriziomello avatar icyberon avatar jaredreisinger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pg_hashids's Issues

Wrong result when encoding bigger numbers

Hey, I was just trying this extension with Postgres 10 and found something odd:

select id_encode(1981515714898, 'salt1', 6, 'ABCDEFGHJKLMNPRSTVXYZ');
 id_encode  
------------
 XDMNVNJPBP
(1 row)


select id_decode('XDMNVNJPBP', 'salt1', 6, 'ABCDEFGHJKLMNPRSTVXYZ');
  id_decode   
--------------
 {1535791442}
(1 row)

The python hashid module returns 'XXAJGNGVJEBX' (and not 'XDMNVNJPBP'), and if I pass that value to id_decode I get back the expected id 1981515714898

Inconsistent results when calling id_encode multiple times in same query

Hi,

The following SQL does not work as expected

SELECT id_encode(table_a.contractid, 'my salt')   AS a_encoded,
       table_a.contractid as a_unencoded,
       id_encode(table_b.id, 'my salt') AS b_encoded,
       table_b.id AS b_unencoded
FROM table_a, table_b

and returns:
a_encoded LJqaROLN8GPb�
a_unencoded 1989354300773498885
b_encoded LJqaROLN8GPbe
b_unencoded 1989354300773498885

both input values (big ints) are the same but notice that one result has an additional character at the end. And yes, I think the first result (a_encoded) is perhaps a null character?

The problem seems worse if I don't use a salt.

The problem does not arise if I only have one id_encode call in a query.

I'm currently using Postgres 11.1 and have just upgraded to the latest GH version of pg_hashids to confirm the problem.

How to make extension in Windows

Hello,

Sorry about my English.

I would like to know how to build the extension using Windows. I installed MingW to compile but it does not recognize the Make command.

Could you give me more instructions to do this on Windows?

Grateful

version 1.1.3: postgres segfault when encoding with custom alphabet

on an up-to-date ubuntu 16.04 LTS, using the latest postgres (12.1), and the latest pg_hashids pg_hashids with HASHIDS_VERSION "1.1.3", id_encode segfaults when using a custom alphabet.

postgres=# SHOW server_version;
          server_version          
----------------------------------
 12.1 (Ubuntu 12.1-1.pgdg18.04+1)
(1 row)

These queries work fine:

postgres=# SELECT id_encode(1001);
 id_encode 
-----------
 jNl
(1 row)

postgres=# SELECT id_encode(1234567, 'This is my salt');
 id_encode 
-----------
 Pdzxp
(1 row)


postgres=# SELECT id_encode(1234567, 'This is my salt', 8);
 id_encode 
-----------
 lRPdzxpR
(1 row)

The custom alphabet segfaults:

postgres=# SELECT id_encode(1234567, 'This is my salt', 8, 'abcdef123456789');
server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

here's the postgres log

2020-01-15 13:36:54.602 PST [31606] LOG:  server process (PID 32146) was terminated by signal 11: Segmentation fault
2020-01-15 13:36:54.602 PST [31606] DETAIL:  Failed process was running: SELECT id_encode(1234567, 'This is my salt', 8, 'abcdef123456789');
2020-01-15 13:36:54.602 PST [31606] LOG:  terminating any other active server processes
2020-01-15 13:36:54.603 PST [32132] WARNING:  terminating connection because of crash of another server process
2020-01-15 13:36:54.603 PST [32132] DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2020-01-15 13:36:54.603 PST [32132] HINT:  In a moment you should be able to reconnect to the database and repeat your command.
2020-01-15 13:36:54.605 PST [32264] postgres@postgres FATAL:  the database system is in recovery mode
2020-01-15 13:36:54.607 PST [31606] LOG:  all server processes terminated; reinitializing
2020-01-15 13:36:54.626 PST [32265] LOG:  database system was interrupted; last known up at 2020-01-15 13:32:19 PST
2020-01-15 13:36:54.665 PST [32265] LOG:  database system was not properly shut down; automatic recovery in progress
2020-01-15 13:36:54.668 PST [32265] LOG:  redo starts at 0/1662F88
2020-01-15 13:36:54.668 PST [32265] LOG:  invalid record length at 0/1662FC0: wanted 24, got 0
2020-01-15 13:36:54.668 PST [32265] LOG:  redo done at 0/1662F88
2020-01-15 13:36:54.695 PST [31606] LOG:  database system is ready to accept connections

error: function id_encode(bigint, unknown, integer, unknown) does not exist

Just pushed an app up to production and started getting this error:

error: function id_encode(bigint, unknown, integer, unknown) does not exist

I'm invoking id_encode like:

CREATE OR REPLACE FUNCTION fourchar_short_id(i BIGINT)
RETURNS TEXT AS $$
DECLARE key TEXT;
BEGIN
  key := id_encode(i, 'mysalt', 4, 'abcdefghkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789-_');
  key := substring(key from 0 for 5);
  RETURN key;
END;
$$ language 'plpgsql';

Haven't seen it in local development at all. I'm trying to track down the mistake I've made and will update this issue for future reference.

Using With Docker and Hasura

Any direction on how to get this working with Docker (and specifically the Heroku image)? It seems like I should be adding this to the docker-compose.yaml, but I'm quite stuck. Any help would be greatly appreciated, thanks!

Better error messages

Right now we're not doing any error handling at all (shame). The next version should fix this. We're going to use ereport everywhere :)

Truncated hash using varchar type under 10.x

I'm working with a codebase which is being upgraded to run on Postgres 10.2 and am using a trigger to generate a hash based on the newly inserting row's id. e.g.

CREATE FUNCTION xy_create_hash() RETURNS trigger AS $$
    BEGIN
        NEW.hash := id_encode(NEW.id, 'mysalt', 6);
        RETURN NEW;
    END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER create_xy_hash BEFORE INSERT ON xy FOR EACH ROW EXECUTE PROCEDURE xy_create_hash();

However, the resulting hash is truncated to 4 valid chars and a DLE char which is encoded as %10 when viewed as part of the url the hash is used to generate.

http://127.0.0.1:3000/foo/w8lV%10/bar

Any idea what could be causing this?

Struggling to install in a dockerized Postgres 9.6

I'm trying to install it to a dockerized Postgres 9.6. The problem is that when running make install command it it does this:

/bin/mkdir -p '/usr/lib/postgresql/13/lib'
/bin/mkdir -p '/usr/share/postgresql/13/extension'
/bin/mkdir -p '/usr/share/postgresql/13/extension'
/usr/bin/install -c -m 755  pg_hashids.so '/usr/lib/postgresql/13/lib/pg_hashids.so'
/usr/bin/install -c -m 644 .//pg_hashids.control '/usr/share/postgresql/13/extension/'
/usr/bin/install -c -m 644 .//pg_hashids--1.3.sql .//pg_hashids--1.2.1--1.3.sql .//pg_hashids--1.2--1.3.sql .//pg_hashids--1.1--1.2.sql .//pg_hashids--1.0--1.1.sql  '/usr/share/postgresql/13/extension/'
/bin/mkdir -p '/usr/lib/postgresql/13/lib/bitcode/pg_hashids'
/bin/mkdir -p '/usr/lib/postgresql/13/lib/bitcode'/pg_hashids/
/usr/bin/install -c -m 644 pg_hashids.bc '/usr/lib/postgresql/13/lib/bitcode'/pg_hashids/./
/usr/bin/install -c -m 644 hashids.bc '/usr/lib/postgresql/13/lib/bitcode'/pg_hashids/./
cd '/usr/lib/postgresql/13/lib/bitcode' && /usr/lib/llvm-6.0/bin/llvm-lto -thinlto -thinlto-action=thinlink -o pg_hashids.index.bc pg_hashids/pg_hashids.bc pg_hashids/hashids.bc

When I try creating the pg_hashids from an sql dump it doesn't find the required files in the extension folder:

ziticity-postgresdb    | ERROR:  could not open extension control file "/usr/share/postgresql/9.6/extension/pg_hashids.control": No such file or directory
ziticity-postgresdb    | STATEMENT:  CREATE EXTENSION IF NOT EXISTS pg_hashids WITH SCHEMA public;
ziticity-postgresdb    | psql:/docker-entrypoint-initdb.d/dump.sql:50: ERROR:  could not open extension control file "/usr/share/postgresql/9.6/extension/pg_hashids.control": No such file or directory

Probably we are am missing a ./configure command, i'm not sure. Please advise

Error creating the pg_hashids extension

After following the steps from README
when I run the command CREATE extension pg_hashids. I get the below error

could not open extension control file "/usr/share/postgresql/13/extension/pg_hashids.control"
how can this be fixed?

Simpler way to link to a query: {decoded_value}

I found way link the hashid to a query but it looks complicated. I want to get rid of the {} returned by id_decode.

Is there a simpler way rather than:

SELECT * FROM mytable,
       (SELECT CAST(translate(id_decode('my_id', 'my_salt', 10)::text, '{}', '') as int4) as id) as hash
                                  WHERE mytable.id = hash.id;

I tried comparing the value directly:

ERROR: operator does not exist: integer = bigint[]

And CAST the result as int4 :

CAST(id_decode('my_id', 'my_salt', 10)::text, '{}', '') as int4)

bigserial return {id}

Hi, thanks for your extension, its very usefull, i'm try to decode and the result its correct. But the return is between keys {15456}, the field is defined like a bigserial. You have any idea?

Convert hash for -1 changes the size of hash

I have installed this extension for converting ids into a hash in my database, we give the size into 3rd parameter after giving salt and alphabets(including letters)
So when I encode -1 in hash it is giving me a length of 16 digits, I don't know why it is giving me a length of 16 characters.

Thanks

Cannot build on OSX 10.14.2

The main issue is that currently I cannot compile pg_hashids, with this versions:

  • OSX: 10.14.2
  • MacOS SDK: MacOSX10.14.sdk
  • PostgreSQL: 10.1

The log is the following:

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.8 -arch i386 -arch x86_64 -O2  -I. -I./ -I/Library/PostgreSQL/10/include/postgresql/server -I/Library/PostgreSQL/10/include/postgresql/internal -I/opt/local/Current/include -I/opt/local/20151229/include/libxml2  -I/opt/local/Current/include/libxml2 -I/opt/local/Current/include  -c -o pg_hashids.o pg_hashids.c
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk' [-Wmissing-sysroot]
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk' [-Wmissing-sysroot]
In file included from pg_hashids.c:1:
In file included from /Library/PostgreSQL/10/include/postgresql/server/postgres.h:47:
/Library/PostgreSQL/10/include/postgresql/server/c.h:81:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.
make: *** [pg_hashids.o] Error 1

Then what I did was install the tools provided by xcode with this:

xcode-select --install

Then I installed macOS SDK Headers with this:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

Inside my /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer folder what I got is this:

├── Library
│   ├── Debugger
│   ├── Frameworks
│   ├── GPUToolsPlatform
│   ├── Instruments
│   ├── Interface\ Builder
│   ├── PrivateFrameworks
│   └── Xcode
├── SDKs
│   ├── MacOSX.sdk
│   └── MacOSX10.14.sdk -> MacOSX.sdk
└── usr
    ├── lib
    └── share

What I tried is to create a symlink to MacOSX.sdk through MacOSX10.8.sdk so the makefile could find it.
But it gives a new error

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.8 -arch i386 -arch x86_64 -O2  -I. -I./ -I/Library/PostgreSQL/10/include/postgresql/server -I/Library/PostgreSQL/10/include/postgresql/internal -I/opt/local/Current/include -I/opt/local/20151229/include/libxml2  -I/opt/local/Current/include/libxml2 -I/opt/local/Current/include  -c -o pg_hashids.o pg_hashids.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.8 -arch i386 -arch x86_64 -O2  -I. -I./ -I/Library/PostgreSQL/10/include/postgresql/server -I/Library/PostgreSQL/10/include/postgresql/internal -I/opt/local/Current/include -I/opt/local/20151229/include/libxml2  -I/opt/local/Current/include/libxml2 -I/opt/local/Current/include  -c -o hashids.o hashids.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.8 -arch i386 -arch x86_64 -O2  -bundle -multiply_defined suppress -o pg_hashids.so pg_hashids.o hashids.o -L/Library/PostgreSQL/10/lib -L/opt/local/Current/lib -L/opt/local/20151229/lib  -Wl,-dead_strip_dylibs   -bundle_loader /Library/PostgreSQL/10/bin/postgres
ld: warning: directory not found for option '-L/opt/local/Current/lib'
ld: warning: directory not found for option '-L/opt/local/20151229/lib'
ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib/libSystem.tbd, missing required architecture i386 in file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib/libSystem.tbd
Undefined symbols for architecture i386:
  "___bzero", referenced from:
      _id_decode in pg_hashids.o
  "___strncat_chk", referenced from:
      _hashids_init3 in hashids.o
      _hashids_encode in hashids.o
      _hashids_decode in hashids.o
  "___udivdi3", referenced from:
      _hashids_encode in hashids.o
  "___umoddi3", referenced from:
      _hashids_encode in hashids.o
  "_calloc", referenced from:
      _id_encode in pg_hashids.o
      _id_encode_array in pg_hashids.o
      _id_decode in pg_hashids.o
      _id_decode_once in pg_hashids.o
      _hashids_alloc_f in hashids.o
  "_ceilf", referenced from:
      _hashids_init3 in hashids.o
  "_floorf", referenced from:
      _hashids_encode in hashids.o
  "_free", referenced from:
      _hashids_free_f in hashids.o
     (maybe you meant: _hashids_free, __hashids_free )
  "_memcpy", referenced from:
      _id_encode in pg_hashids.o
      _id_encode_array in pg_hashids.o
      _id_decode in pg_hashids.o
      _id_decode_once in pg_hashids.o
  "_memmove", referenced from:
      _hashids_init3 in hashids.o
      _hashids_encode in hashids.o
  "_strchr", referenced from:
      _hashids_init3 in hashids.o
      _hashids_numbers_count in hashids.o
      _hashids_decode in hashids.o
  "_strlen", referenced from:
      _hashids_init3 in hashids.o
      _hashids_encode_hex in hashids.o
  "_strncpy", referenced from:
      _id_encode in pg_hashids.o
      _id_encode_array in pg_hashids.o
      _hashids_init3 in hashids.o
      _hashids_encode in hashids.o
      _hashids_decode in hashids.o
      _hashids_encode_hex in hashids.o
  "_strtoull", referenced from:
      _hashids_encode_hex in hashids.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_hashids.so] Error 1

strange behaviour of "UPDATE" with id_encode()

Hi,

(NOTE this is also posted here docker-library/postgres#1122 (comment))

I'm running a kubernetes instance of 15.4-alpine3.18, with modified image IMG_POSTGRES_TAG added with pg_hashids via following Dockerfile:

FROM postgres:15.4-alpine3.18                                                                                                                                                                                                                 
 
RUN apk add --no-cache --virtual .build-deps build-base postgresql-dev clang15 llvm15 ; \
    wget -qO- https://github.com/iCyberon/pg_hashids/archive/refs/tags/v1.2.1.tar.gz | tar xzf - -C /tmp && \
    make -C /tmp/pg_hashids-1.2.1 && \
    make -C /tmp/pg_hashids-1.2.1 install && \
    rm -rf /tmp/pg_hashids-1.2.1 && \
    apk del .build-deps

Deployed to the cluster with:

helm install postgres --set image.repository=postgres,image.tag=${IMG_POSTGRES_TAG},primary.service.clusterIP=${POSTGRES_CLUSTER_IP},primary.persistence.existingClaim=postgres oci://registry-1.docker.io/bitnamicharts/postgresql

The issue is that a trigger function which generates hashes during insert, miss-behaves and generates a wrong hash ending with a space.

Reproduce it by running the following SQL:

BEGIN;
DROP SCHEMA IF EXISTS test CASCADE;
CREATE SCHEMA test;
CREATE TABLE test.test (
    id bigint NOT NULL,
    data text,
    ids text,
    ids1 text,
    ids2 text
);
CREATE SEQUENCE test.test_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER SEQUENCE test.test_id_seq OWNED BY test.test.id;
ALTER TABLE ONLY test.test
    ALTER COLUMN id SET DEFAULT nextval('test.test_id_seq'::regclass);
CREATE FUNCTION test.myfunc ()
    RETURNS TRIGGER
    LANGUAGE plpgsql
    AS $$
BEGIN
    UPDATE
        test.test
    SET
        ids = id_encode (NEW.id, 'hash1', 5, 'abcdefghijklmnopqrstuvwxyz'),
        ids1 = id_encode (NEW.id, 'hash2', 12, 'abcdefghijklmnopqrstuvwxyz'),
        ids2 = id_encode (NEW.id, 'hash3', 12, 'abcdefghijklmnopqrstuvwxyz')
    WHERE
        id = NEW.id;
    RETURN new;
END;
$$;
CREATE FUNCTION test.myfunc_fix ()
    RETURNS TRIGGER
    LANGUAGE plpgsql
    AS $$
BEGIN
    UPDATE
        test.test
    SET
        ids = id_encode (NEW.id, 'hash1', 5, 'abcdefghijklmnopqrstuvwxyz')
    WHERE
        id = NEW.id;
    UPDATE
        test.test
    SET
        ids1 = id_encode (NEW.id, 'hash2', 12, 'abcdefghijklmnopqrstuvwxyz'),
        ids2 = id_encode (NEW.id, 'hash3', 12, 'abcdefghijklmnopqrstuvwxyz')
    WHERE
        id = NEW.id;
    RETURN new;
END;
$$;
CREATE TRIGGER test_myfunc
    AFTER INSERT ON test.test
    FOR EACH ROW
    EXECUTE FUNCTION test.myfunc ();
\copy test.test to stdout CSV FORCE QUOTE *;
INSERT INTO test.test (data)
    VALUES ('a'),
    ('b');
\copy test.test to stdout CSV FORCE QUOTE *;
DROP TRIGGER test_myfunc ON test.test;
CREATE TRIGGER test_myfunc_fix
    AFTER INSERT ON test.test
    FOR EACH ROW
    EXECUTE FUNCTION test.myfunc_fix ();
\copy test.test to stdout CSV FORCE QUOTE *;
INSERT INTO test.test (data)
    VALUES ('a1'),
    ('b1');
\copy test.test to stdout CSV FORCE QUOTE *;
COMMIT

Run it with: cat test.sql | psq -U testdb.

Output looks like:

WARNING:  database "testdb" has no actual collation version, but a version was recorded
BEGIN
NOTICE:  drop cascades to 3 other objects
DETAIL:  drop cascades to table test.test
drop cascades to function test.myfunc()
drop cascades to function test.myfunc_fix()
DROP SCHEMA
CREATE SCHEMA
CREATE TABLE
CREATE SEQUENCE
ALTER SEQUENCE
ALTER TABLE
CREATE FUNCTION
CREATE FUNCTION
CREATE TRIGGER
INSERT 0 2
"1","a","zmnb ","wzejgmprmnpa","yzvmbrydnogd"
"2","b","pylw ","xabdomywmenl","zmbexnawnpaq"
DROP TRIGGER
CREATE TRIGGER
"1","a","zmnb ","wzejgmprmnpa","yzvmbrydnogd"
"2","b","pylw ","xabdomywmenl","zmbexnawnpaq"
INSERT 0 2
"1","a","zmnb ","wzejgmprmnpa","yzvmbrydnogd"
"2","b","pylw ","xabdomywmenl","zmbexnawnpaq"
"3","a1","zmpdm","jlyezmrwvakd","ybjwprgzndxl"
"4","b1","dmepy","ydqlpvjrvxnz","jwmvprxmnkea"
COMMIT

The issue is the space in the end of "zmnb ". Utilizing myfunc_fix() which basically runs separated UPDATE, works i.e. generates hashes without the trailing space. But I am not at all satisfied and I would like to understand what is the root cause?!?!

I noticed the WARNING: database "testdb" has no actual collation version, but a version was recorded and I am not sure how that is realted (I do not really know what is the impact of that.

Any help or ideas?

Cheers,
DataSelfService team

Several PostgreSQL versions

Hello,

How to choose the pg version for make/make install ? It's deployed in 9.3 but not in 9.6 (I have both and I want to use it in 9.6).

Thanks

[edit] Ok I succeeded to deploy if by removing one or the other pg sources. But this is not very user friendly.

Segmentation fault (Postgres crash)

Hi,

I'm using pg_hashids v1.2.1 and have found that the following code will crash the Postgres Postmaster:

SELECT id_decode(null);

and this in the Postgres logs:

2019-02-24 21:16:51.332 UTC [1] LOG:  server process (PID 49322) was terminated by signal 11: Segmentation fault
2019-02-24 21:16:51.332 UTC [1] DETAIL:  Failed process was running: SELECT id_decode(null)
2019-02-24 21:16:51.332 UTC [1] LOG:  terminating any other active server processes
2019-02-24 21:16:51.333 UTC [49319] WARNING:  terminating connection because of crash of another server process

I'm not sure what the correct behaviour ought to be (to return NULL or {0}) but believe an outright crash should be avoidable?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.