Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: call to undeclared function 'PG_GETARG_RANGE' #1

Open
ben-sandham opened this issue Dec 15, 2023 · 1 comment
Open

error: call to undeclared function 'PG_GETARG_RANGE' #1

ben-sandham opened this issue Dec 15, 2023 · 1 comment

Comments

@ben-sandham
Copy link

Environment Details

clang --version
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
psql --version
psql (PostgreSQL) 16.1 (Homebrew)

Description

When trying to install the extension, I encountered the following issue.

make && sudo make install
clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -O2  -fvisibility=hidden -I. -I./ -I/opt/homebrew/opt/postgresql@16/include/postgresql/server -I/opt/homebrew/opt/postgresql@16/include/postgresql/internal -I/opt/homebrew/Cellar/icu4c/73.2/include -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/Cellar/lz4/1.9.4/include   -c -o time_for_keys.o time_for_keys.c
clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -O2  -fvisibility=hidden -I. -I./ -I/opt/homebrew/opt/postgresql@16/include/postgresql/server -I/opt/homebrew/opt/postgresql@16/include/postgresql/internal -I/opt/homebrew/Cellar/icu4c/73.2/include -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/Cellar/lz4/1.9.4/include   -c -o completely_covers.o completely_covers.c
completely_covers.c:84:20: error: call to undeclared function 'PG_GETARG_RANGE'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    target_range = PG_GETARG_RANGE(2);
                   ^
completely_covers.c:84:18: warning: incompatible integer to pointer conversion assigning to 'RangeType *' from 'int' [-Wint-conversion]
    target_range = PG_GETARG_RANGE(2);
                 ^ ~~~~~~~~~~~~~~~~~~
completely_covers.c:110:20: error: call to undeclared function 'PG_GETARG_RANGE'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    target_range = PG_GETARG_RANGE(2);
                   ^
completely_covers.c:110:18: warning: incompatible integer to pointer conversion assigning to 'RangeType *' from 'int' [-Wint-conversion]
    target_range = PG_GETARG_RANGE(2);
                 ^ ~~~~~~~~~~~~~~~~~~
completely_covers.c:121:19: error: call to undeclared function 'PG_GETARG_RANGE'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  current_range = PG_GETARG_RANGE(1);
                  ^
completely_covers.c:121:17: warning: incompatible integer to pointer conversion assigning to 'RangeType *' from 'int' [-Wint-conversion]
  current_range = PG_GETARG_RANGE(1);
                ^ ~~~~~~~~~~~~~~~~~~
3 warnings and 3 errors generated.
make: *** [completely_covers.o] Error 1

Issue

Make DatumGetFoo/PG_GETARG_FOO/PG_RETURN_FOO macro names more consistent renamed the PG_GETARG_RANGE macro to PG_GETARG_RANGE_P.

Fix

I do not have contributor abilities to the repo, but the fix should be as simple as changing all references of PG_GETARG_RANGE to PG_GETARG_RANGE_P. Afterwards I had no issue installing the extension and running create_temporal_foreign_key_test.sql.

make && sudo make install
clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -O2  -fvisibility=hidden -I. -I./ -I/opt/homebrew/opt/postgresql@16/include/postgresql/server -I/opt/homebrew/opt/postgresql@16/include/postgresql/internal -I/opt/homebrew/Cellar/icu4c/73.2/include -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/Cellar/lz4/1.9.4/include   -c -o completely_covers.o completely_covers.c
clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -O2  -fvisibility=hidden -bundle -o time_for_keys.dylib time_for_keys.o completely_covers.o  -L/opt/homebrew/opt/postgresql@16/lib  -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk -L/opt/homebrew/opt/gettext/lib -L/opt/homebrew/opt/openssl@3/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/Cellar/lz4/1.9.4/lib  -Wl,-dead_strip_dylibs   -fvisibility=hidden -bundle_loader /opt/homebrew/Cellar/postgresql@16/16.1_1/bin/postgres
Password:
/bin/sh /opt/homebrew/opt/postgresql@16/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -d '/opt/homebrew/opt/postgresql@16/lib/postgresql'
/bin/sh /opt/homebrew/opt/postgresql@16/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -d '/opt/homebrew/opt/postgresql@16/share/postgresql@16/extension'
/bin/sh /opt/homebrew/opt/postgresql@16/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -d '/opt/homebrew/opt/postgresql@16/share/postgresql@16/extension'
/usr/bin/install -c -m 755  time_for_keys.dylib '/opt/homebrew/opt/postgresql@16/lib/postgresql/time_for_keys.dylib'
/usr/bin/install -c -m 644 .//time_for_keys.control '/opt/homebrew/opt/postgresql@16/share/postgresql@16/extension/'
/usr/bin/install -c -m 644 .//time_for_keys--0.0.1.sql  '/opt/homebrew/opt/postgresql@16/share/postgresql@16/extension/'
psql postgres
psql (16.1 (Homebrew))
Type "help" for help.

postgres=# CREATE EXTENSION time_for_keys;
CREATE EXTENSION
postgres=# CREATE EXTENSION btree_gist;
CREATE EXTENSION
postgres=# CREATE TABLE shifts (
  job_id INTEGER,
  worker_id INTEGER,
  valid_at tstzrange,
  EXCLUDE USING gist (worker_id WITH =, valid_at WITH &&)
);
CREATE TABLE houses (
  id INTEGER,
  assessment FLOAT,
  valid_at tstzrange,
  CONSTRAINT tpk_houses_id EXCLUDE USING gist (id WITH =, valid_at WITH &&) DEFERRABLE INITIALLY IMMEDIATE
);
CREATE TABLE rooms (
  id INTEGER,
  house_id INTEGER,
  valid_at tstzrange,
  CONSTRAINT tpk_rooms_id EXCLUDE USING gist (id WITH =, valid_at WITH &&) DEFERRABLE INITIALLY IMMEDIATE
);
CREATE TABLE
CREATE TABLE
CREATE TABLE
postgres=# INSERT INTO houses VALUES
  (1, 150000, tstzrange('2015-01-01', '2016-01-01')),
  (1, 200000, tstzrange('2016-01-01', '2017-01-01'))
;
INSERT 0 2
postgres=# SELECT create_temporal_foreign_key('room_has_a_house', 'rooms', 'house_id', 'valid_at', 'houses', 'id', 'valid_at');
SELECT drop_temporal_foreign_key('room_has_a_house', 'rooms', 'houses');
 create_temporal_foreign_key
-----------------------------

(1 row)

 drop_temporal_foreign_key
---------------------------

(1 row)

postgres=# -- it works on a table with a NULL foreign key
INSERT INTO rooms VALUES (1, NULL, tstzrange('2015-01-01', '2017-01-01'));
SELECT create_temporal_foreign_key('room_has_a_house', 'rooms', 'house_id', 'valid_at', 'houses', 'id', 'valid_at');
SELECT drop_temporal_foreign_key('room_has_a_house', 'rooms', 'houses');
DELETE FROM rooms;

-- it works on a table with a FK fulfilled by one row
INSERT INTO rooms VALUES (1, 1, tstzrange('2015-01-01', '2016-01-01'));
SELECT create_temporal_foreign_key('room_has_a_house', 'rooms', 'house_id', 'valid_at', 'houses', 'id', 'valid_at');
SELECT drop_temporal_foreign_key('room_has_a_house', 'rooms', 'houses');
DELETE FROM rooms;

-- it works on a table with a FK fulfilled by two rows
INSERT INTO rooms VALUES (1, 1, tstzrange('2015-01-01', '2016-06-01'));
SELECT create_temporal_foreign_key('room_has_a_house', 'rooms', 'house_id', 'valid_at', 'houses', 'id', 'valid_at');
SELECT drop_temporal_foreign_key('room_has_a_house', 'rooms', 'houses');
DELETE FROM rooms;

-- it fails on a table with a missing foreign key
INSERT INTO rooms VALUES (1, 2, tstzrange('2015-01-01', '2016-01-01'));
SELECT create_temporal_foreign_key('room_has_a_house', 'rooms', 'house_id', 'valid_at', 'houses', 'id', 'valid_at');
DELETE FROM rooms;

-- it fails on a table with a completely-uncovered foreign key
INSERT INTO rooms VALUES (1, 1, tstzrange('2010-01-01', '2011-01-01'));
SELECT create_temporal_foreign_key('room_has_a_house', 'rooms', 'house_id', 'valid_at', 'houses', 'id', 'valid_at');
DELETE FROM rooms;

-- it fails on a table with a partially-covered foreign key
INSERT INTO rooms VALUES (1, 1, tstzrange('2015-01-01', '2018-01-01'));
SELECT create_temporal_foreign_key('room_has_a_house', 'rooms', 'house_id', 'valid_at', 'houses', 'id', 'valid_at');
DELETE FROM rooms;

DELETE FROM rooms;
DELETE FROM houses;
INSERT 0 1
 create_temporal_foreign_key
-----------------------------

(1 row)

 drop_temporal_foreign_key
---------------------------

(1 row)

DELETE 1
INSERT 0 1
 create_temporal_foreign_key
-----------------------------

(1 row)

 drop_temporal_foreign_key
---------------------------

(1 row)

DELETE 1
INSERT 0 1
 create_temporal_foreign_key
-----------------------------

(1 row)

 drop_temporal_foreign_key
---------------------------

(1 row)

DELETE 1
INSERT 0 1
ERROR:  Tried to insert 2 to rooms.house_id but couldn't find it in houses.id for all of [2015-01-01 00:00:00-05, 2016-01-01 00:00:00-05)
CONTEXT:  PL/pgSQL function tri_fkey_check(text,text,text,text,text,text,integer,tstzrange,boolean) line 25 at RAISE
SQL statement "SELECT TRI_FKey_check(
      from_table, from_column, from_range_column,
      to_table,   to_column,   to_range_column,
      fk_val, from_range, false)"
PL/pgSQL function create_temporal_foreign_key(text,text,text,text,text,text,text) line 92 at PERFORM
DELETE 1
INSERT 0 1
ERROR:  Tried to insert 1 to rooms.house_id but couldn't find it in houses.id for all of [2010-01-01 00:00:00-05, 2011-01-01 00:00:00-05)
CONTEXT:  PL/pgSQL function tri_fkey_check(text,text,text,text,text,text,integer,tstzrange,boolean) line 25 at RAISE
SQL statement "SELECT TRI_FKey_check(
      from_table, from_column, from_range_column,
      to_table,   to_column,   to_range_column,
      fk_val, from_range, false)"
PL/pgSQL function create_temporal_foreign_key(text,text,text,text,text,text,text) line 92 at PERFORM
DELETE 1
INSERT 0 1
ERROR:  Tried to insert 1 to rooms.house_id but couldn't find it in houses.id for all of [2015-01-01 00:00:00-05, 2018-01-01 00:00:00-05)
CONTEXT:  PL/pgSQL function tri_fkey_check(text,text,text,text,text,text,integer,tstzrange,boolean) line 25 at RAISE
SQL statement "SELECT TRI_FKey_check(
      from_table, from_column, from_range_column,
      to_table,   to_column,   to_range_column,
      fk_val, from_range, false)"
PL/pgSQL function create_temporal_foreign_key(text,text,text,text,text,text,text) line 92 at PERFORM
DELETE 1
DELETE 0
DELETE 2
postgres=#
@pjungwir
Copy link
Owner

Thanks for taking a look at this extension! Postgres renamed that macro to PG_GETARG_RANGE_P several versions ago, and I haven't updated this extension. To be honest it is more of a proof of concept that something intended for production. If you are interested in getting the same features with better support, you should check out Vik Fearing's periods extension. Or hopefully this will all be in core soon (see the commitfest page).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants