Giter VIP home page Giter VIP logo

pguint's Introduction

Unsigned and other extra integer types for PostgreSQL

This extension provides additional integer types for PostgreSQL:

  • int1 (signed 8-bit integer)
  • uint1 (unsigned 8-bit integer)
  • uint2 (unsigned 16-bit integer)
  • uint4 (unsigned 32-bit integer)
  • uint8 (unsigned 64-bit integer)

Installation

PostgreSQL version 9.1 or later is required. Currently, only 64-bit builds are supported.

To build and install this module:

make
make install

or selecting a specific PostgreSQL installation:

make PG_CONFIG=/some/where/bin/pg_config
make PG_CONFIG=/some/where/bin/pg_config install

And finally inside the database:

CREATE EXTENSION uint;

Using

You can use the new types like the standard integer types. Examples:

CREATE TABLE foo (
    a uint4,
    b text
);

SELECT * FROM foo WHERE a > 4;

SELECT avg(a) FROM foo;

The types come with a sizable set of operators and functions, index support, etc. Some pieces are still missing, but they are being worked on. If there is anything you can't find, let me know.

Discussion

Support for unsigned integer types and smaller integer types has been one of the more common outstanding feature request for PostgreSQL. Inclusion of additional integer types into the core is typically rejected with the argument that it would make the type system too complicated and fragile. The experience from writing this module suggests: That is not wrong. Another argument, either explicit or implicit, is that it is a lot of work. Again: true.

The combination of the requirements of the SQL standard and the type system of PostgreSQL effectively create a situation where you need to provide a comprehensive set of operators and functions for each combination of numeric types. So for the three standard integer types, that's 9 "+" operators, 9 "<" operators, and so on. And with 3 + 5 = 8 types, well, you do the math. This module solves that problem by generating most of the code automatically.

The purpose of this module is therefore twofold: First, it should be useful in practice. There is no reason why it couldn't be. Second, it is a challenge to the PostgreSQL extension mechanism. In that area, there are various "interesting" problems that still need to be worked out.

Testing

In addition to the test suite of this module (make installcheck), it is useful to test this module by running the main PostgreSQL regression tests while this module is loaded, which should not fail. This will verify that the presence of the additional types and operators will not cause changes in the interpretation of expressions involving the existing types and operators.

pguint's People

Contributors

petere 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  avatar  avatar  avatar  avatar  avatar

pguint's Issues

segfault on insert

successfully installed proger10 fork on 9.6 (centos 7), registered (CREATE EXTENSION uint) and created public.uint8 field in table but whenever I try to insert record there pgsql crashes with segfault

Problem Installation (Windows 10 x64)

make

process_begin: CreateProcess((null), pg_config --version, ...) failed.
process_begin: CreateProcess((null), pg_config --includedir-server, ...) failed.
"grep" is not internal or external
command, executable program or batch file.
process_begin: CreateProcess((null), pg_config --pgxs, ...) failed.
makefile:29: no file name for `include'
cat uint.sql hash.sql hex.sql operators.sql | sed 's/@UINT8_PASSEDBYVALUE@//' >uint--0.sql
"cat" is not internal or external
command, executable program or batch file.
make: *** [uint--0.sql] Error 255

make install

process_begin: CreateProcess((null), pg_config --version, ...) failed.
process_begin: CreateProcess((null), pg_config --includedir-server, ...) failed.
"grep" is not internal or external
command, executable program or batch file.
process_begin: CreateProcess((null), pg_config --pgxs, ...) failed.
makefile:29: no file name for include' make: *** No rule to make target install'. Stop.

Creation failed in PG11

Hi, I have tried to install the extension in PG11 but I got plenty warnings and notes:
implicit declaration of function ‘GET_1_BYTE’ [-Wimplicit-function-declaration]
or
implicit declaration of function 'GET_1_BYTE' is invalid in C99 [-Wimplicit-function-declaration]

After "successful" compilation, linking, and installation the extension was not created, displaying the following error:
SQL Error [XX000]: ERROR: could not load library "/usr/lib/postgresql/11/lib/uint.so": /usr/lib/postgresql/11/lib/uint.so: undefined symbol: GET_1_BYTE

I tried to change the code in unit.h but I failed to make it run. With my little knowledge and recent "bad" experience I suspect it may not be only a matter of correct declaration but maybe beyond that.

Tia

PS: In PG10, the extension was created without any problem.

Add binary input-output support

Some postgresql libraries transfers data using binary format only. For example postgres and sqlx crates in rust. Unfortunately they can't be used together with this extension because of lack of binary send/receive functions.

unsigned integer arithmetics

it is supposed to be modulo arithmetics.
i.e. 2-1 = 1 and 1-2 = 255 for uint1
and 1 - 2 = 65535 for uint2

why it is not implemented like this but with some condition check and error report?
For example functions uint8uint8pl or uint8uint8mi break modulo arithmetics.

Problem Installation (Windows 10 x64) (sorry, new problem)

make

grep: 1': No such file or directory
grep: C:/OSPanel/modules/database/PostgreSQL-10.1-x64/include/server/pg_config.h: No such file or directory
makefile:29: C:/OSPanel/modules/database/PostgreSQL-10.1-x64/lib/pgxs/src/makefiles/pgxs.mk: No such file or directory
make: *** No rule to make target `C:/OSPanel/modules/database/PostgreSQL-10.1-x64/lib/pgxs/src/makefiles/pgxs.mk'. Stop.

make install

grep: 1': No such file or directory
grep: C:/OSPanel/modules/database/PostgreSQL-10.1-x64/include/server/pg_config.h: No such file or directory
makefile:29: C:/OSPanel/modules/database/PostgreSQL-10.1-x64/lib/pgxs/src/makefiles/pgxs.mk: No such file or directory
make: *** No rule to make target `C:/OSPanel/modules/database/PostgreSQL-10.1-x64/lib/pgxs/src/makefiles/pgxs.mk'. Stop.

Json operators treat pguint as strings...

create table crap (test integer);
CREATE TABLE
insert into crap values (456);
INSERT 0 1
select row_to_json(crap) as j from crap;
      j
--------------
 {"test":456}

But if instead I use...

create table crap2 (test uint4);
CREATE TABLE
insert into crap2 values (456);
INSERT 0 1
select row_to_json(crap2) as j from crap2;
       j
----------------
 {"test":"456"}

This is a minor nitpick of course. I was hoping that there's some clever create cast statement that will resolve the issue. Or would a solution need to be more involved than this?

New integer type

Hello.
Is it possible to add another type of integer MEDIUMINT (24 bit)?

After clone and just make it does not build

$ make
clang -Wall ................................................................. -c -o misc.o misc.c
generate.py 16
make: generate.py: No such file or directory
make: *** [operators.c] Error 1

I managed to build by running python3 generate.py 16 before make

So, if I do not do anything wrong, README should instruct to do so, before make.

Can't run "make"

There is an issue with your makefiles. I'm having the same problem with all your postgresql extensions. Perhaps the makefiles need to be updated. I try to manually give the makefile the path to my config.h in terminal, but I'm getting permission denied errors even when using sudo.

install problem...

OS: Ubuntu server 16.04 x64

PostgreSQL 10.2...

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -We                  ndif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -f                  wrapv -fexcess-precision=standard -g -g -O2 -fstack-protector-strong -Wformat -W                  error=format-security -fPIC -pie -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/i                  nclude/postgresql/10/server -I/usr/include/postgresql/internal -I/usr/include/x8                  6_64-linux-gnu -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libx                  ml2  -I/usr/include/mit-krb5  -c -o aggregates.o aggregates.c

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -We                  ndif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -f                  wrapv -fexcess-precision=standard -g -g -O2 -fstack-protector-strong -Wformat -W                  error=format-security -fPIC -pie -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/i                  nclude/postgresql/10/server -I/usr/include/postgresql/internal -I/usr/include/x8                  6_64-linux-gnu -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libx                  ml2  -I/usr/include/mit-krb5  -c -o hash.o hash.c

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -We                  ndif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -f                  wrapv -fexcess-precision=standard -g -g -O2 -fstack-protector-strong -Wformat -W                  error=format-security -fPIC -pie -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/i                  nclude/postgresql/10/server -I/usr/include/postgresql/internal -I/usr/include/x8                  6_64-linux-gnu -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libx                  ml2  -I/usr/include/mit-krb5  -c -o hex.o hex.c

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -We                  ndif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -f                  wrapv -fexcess-precision=standard -g -g -O2 -fstack-protector-strong -Wformat -W                  error=format-security -fPIC -pie -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/i                  nclude/postgresql/10/server -I/usr/include/postgresql/internal -I/usr/include/x8                  6_64-linux-gnu -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libx                  ml2  -I/usr/include/mit-krb5  -c -o inout.o inout.c

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -We                  ndif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -f                  wrapv -fexcess-precision=standard -g -g -O2 -fstack-protector-strong -Wformat -W                  error=format-security -fPIC -pie -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/i                  nclude/postgresql/10/server -I/usr/include/postgresql/internal -I/usr/include/x8                  6_64-linux-gnu -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libx                  ml2  -I/usr/include/mit-krb5  -c -o magic.o magic.c

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -We                  ndif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -f                  wrapv -fexcess-precision=standard -g -g -O2 -fstack-protector-strong -Wformat -W                  error=format-security -fPIC -pie -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/i                  nclude/postgresql/10/server -I/usr/include/postgresql/internal -I/usr/include/x8                  6_64-linux-gnu -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libx                  ml2  -I/usr/include/mit-krb5  -c -o misc.o misc.c

/usr/bin/python generate.py 10.2
make: /usr/bin/python: Команда не найдена
Makefile:37: ошибка выполнения рецепта для цели «operators.c»
make: *** [operators.c] Ошибка 127

GCC 13 build error

Hi @petere ,

Latest pguint release fails to build on Fedora 38, which uses GCC 13.2. Can you please take a look? Error is below.

Thanks! Devrim

/usr/lib64/ccache/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Xclang -no-opaque-pointers -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -O2 -I. -I./ -I/usr/pgsql-16/include/server -I/usr/pgsql-16/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include -flto=thin -emit-llvm -c -o hash.bc hash.c
In file included from inout.c:5:
inout.c: In function 'int1in':
inout.c:17:24: warning: implicit declaration of function 'pg_atoi'; did you mean 'pg_ltoa'? [-Wimplicit-function-declaration]
17 | PG_RETURN_INT8(pg_atoi(s, sizeof(int8), '\0'));
| ^~~~~~~
uint.h:29:53: note: in definition of macro 'PG_RETURN_INT8'
29 | #define PG_RETURN_INT8(x) return Int8GetDatum(x)
| ^
/usr/lib64/ccache/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Xclang -no-opaque-pointers -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -O2 -I. -I./ -I/usr/pgsql-16/include/server -I/usr/pgsql-16/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include -flto=thin -emit-llvm -c -o hex.bc hex.c
/usr/lib64/ccache/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Xclang -no-opaque-pointers -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -O2 -I. -I./ -I/usr/pgsql-16/include/server -I/usr/pgsql-16/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include -flto=thin -emit-llvm -c -o inout.bc inout.c
/usr/lib64/ccache/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Xclang -no-opaque-pointers -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -O2 -I. -I./ -I/usr/pgsql-16/include/server -I/usr/pgsql-16/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include -flto=thin -emit-llvm -c -o magic.bc magic.c
/usr/lib64/ccache/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Xclang -no-opaque-pointers -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -O2 -I. -I./ -I/usr/pgsql-16/include/server -I/usr/pgsql-16/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include -flto=thin -emit-llvm -c -o misc.bc misc.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fPIC -fvisibility=hidden -I. -I./ -I/usr/pgsql-16/include/server -I/usr/pgsql-16/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include -c -o operators.o operators.c
/usr/lib64/ccache/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Xclang -no-opaque-pointers -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -O2 -I. -I./ -I/usr/pgsql-16/include/server -I/usr/pgsql-16/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include -flto=thin -emit-llvm -c -o operators.bc operators.c
cat uint.sql hash.sql hex.sql operators.sql >uint--0.sql
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fPIC -fvisibility=hidden -shared -o uint.so aggregates.o hash.o hex.o inout.o magic.o misc.o operators.o -L/usr/pgsql-16/lib -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -L/usr/lib64 -L/usr/lib64 -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-16/lib',--enable-new-dtags -fvisibility=hidden
inout.c:17:17: error: call to undeclared function 'pg_atoi'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
PG_RETURN_INT8(pg_atoi(s, sizeof(int8), '\0'));
^
1 error generated.

Install problem

Hi,

On my Debian 11 machine, make returns with this error :

make: generate.py: No such file or directory
make: *** [Makefile:33: operators.c] Error 127

I eventually managed to compile the extension, but I had to copy the file generate.py in my postgres install path, and I had to insert the following line at the top of it :

#!/usr/bin/python

Problem Installation (Ubuntu 17.10.1 x64 and PostgreSQL 9.6.6) (sorry, new problem...)

make

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -g -O2 -fdebug-prefix-map=/build/postgresql-9.6-L_AOyy/postgresql-9.6-9.6.6=. -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/include/postgresql/9.6/server -I/usr/include/postgresql/internal -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5 -c -o aggregates.o aggregates.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -g -O2 -fdebug-prefix-map=/build/postgresql-9.6-L_AOyy/postgresql-9.6-9.6.6=. -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/include/postgresql/9.6/server -I/usr/include/postgresql/internal -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5 -c -o hash.o hash.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -g -O2 -fdebug-prefix-map=/build/postgresql-9.6-L_AOyy/postgresql-9.6-9.6.6=. -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/include/postgresql/9.6/server -I/usr/include/postgresql/internal -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5 -c -o hex.o hex.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -g -O2 -fdebug-prefix-map=/build/postgresql-9.6-L_AOyy/postgresql-9.6-9.6.6=. -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/include/postgresql/9.6/server -I/usr/include/postgresql/internal -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5 -c -o inout.o inout.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -g -O2 -fdebug-prefix-map=/build/postgresql-9.6-L_AOyy/postgresql-9.6-9.6.6=. -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/include/postgresql/9.6/server -I/usr/include/postgresql/internal -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5 -c -o magic.o magic.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -g -O2 -fdebug-prefix-map=/build/postgresql-9.6-L_AOyy/postgresql-9.6-9.6.6=. -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/include/postgresql/9.6/server -I/usr/include/postgresql/internal -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5 -c -o misc.o misc.c

/usr/bin/python generate.py 9.6.6
make: /usr/bin/python: Command not found
Makefile:37: failed to perform the recipe for the target «operators.c»
make: *** [operators.c] Error 127

make install

/usr/bin/python generate.py 9.6.6
make: /usr/bin/python: Command not found
Makefile:37: failed to perform the recipe for the target «operators.c»
make: *** [operators.c] Error 127

Inverted error condition when adding or subtracting negative int4

When adding or subtracting a negative int4 to a uint4, the "integer out of range" error condition appears to be inverted.

Example:

postgres=# select 0::uint4 + (-1::int4);
  ?column?  
------------
 4294967295
(1 row)
postgres=# select 0::uint4 - (-1::int4);
ERROR:  integer out of range

Expected output:

postgres=# select 0::uint4 + (-1::int4);
ERROR:  integer out of range
postgres=# select 0::uint4 - (-1::int4);
 ?column? 
----------
        1
(1 row)

Has anyone figured out how to add this extension to a schema?

For example, if I do something like (in a database we will call mydb):

CREATE SCHEMA x;
CREATE EXTENSION uint WITH SCHEMA x;

SELECT (5::x.uint4=5::x.uint4);
ERROR:  operator is not unique: x.uint4 = x.uint4
LINE 1: select (5::x.uint4=5::x.uint4);
                          ^
HINT:  Could not choose a best candidate operator. You might need to add explicit type casts.

For some reason, the uint extension being installed in a schema seems to break the included comparison operators.

If I cast the uint4 to say bigint, I can compare once again, showing that it is fine with the x.uint4 type, it just doesn't know how to compare to uint4's using the comparison functions built into the extension:

select (5::x.uint4::bigint=5::x.uint4::bigint);
 ?column? 
----------
 t
(1 row)

I can bypass this by adding a search path:

ALTER DATABASE mydb SET search_path TO x;
-- Might need to reconnect for it to take effect
select (5::uint4=5::uint4);
 ?column? 
----------
 t
(1 row)

It can now find the equality operator in the search path (and the uint4 type in the x SCHEMA), but this is a total hack. I would imagine that the uint extension should prequalify comparators automatically with the SCHEMA to which it was installed (i.e., SCHEMA x in my example).

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.