Skip to content

Commit 2f3b020

Browse files
committed
Add PostgreSQL 19 compatibility
1 parent 7e7a8d9 commit 2f3b020

6 files changed

Lines changed: 234 additions & 6 deletions

File tree

include/clientauth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
* contains the changes needed by uni_api to load the functionality for
1919
* clientauth.
2020
*/
21-
void clientauth_init();
21+
void clientauth_init(void);

include/compatibility.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,11 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext,
382382
CastCreate(sourcetypeid, targettypeid, funcid, castcontext, castmethod, behavior)
383383
#endif
384384

385-
#if PG_VERSION_NUM >= 140000
385+
#if PG_VERSION_NUM >= 190000
386+
#define FUNCNAME_GET_CANDIDATES(names, nargs, argnames, expand_variadic, expand_defaults, missing_ok) \
387+
({ int _fgc_flags = 0; \
388+
FuncnameGetCandidates(names, nargs, argnames, expand_variadic, expand_defaults, false /* include_out_arguments */, missing_ok, &_fgc_flags); })
389+
#elif PG_VERSION_NUM >= 140000
386390
#define FUNCNAME_GET_CANDIDATES(names, nargs, argnames, expand_variadic, expand_defaults, missing_ok) \
387391
FuncnameGetCandidates(names, nargs, argnames, expand_variadic, expand_defaults, false /* include_out_arguments */, missing_ok)
388392
#else
@@ -635,4 +639,22 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext,
635639
ExecutorRun((queryDesc), (direction), (count), (execute_once))
636640
#endif
637641

642+
/*
643+
* PostgreSQL version 19
644+
*
645+
* pgstat.h no longer transitively includes utils/wait_event.h
646+
* log_min_messages changed from int to int[]
647+
* get_database_name moved to utils/lsyscache.h
648+
* get_database_oid moved to catalog/pg_database.h
649+
* CreateSchemaCommand signature changed to (ParseState*, CreateSchemaStmt*, int, int)
650+
*/
651+
#if (PG_VERSION_NUM >= 190000)
652+
#include "utils/wait_event.h"
653+
#include "catalog/pg_database.h"
654+
#include "utils/lsyscache.h"
655+
#define LOG_MIN_MESSAGES_VALUE log_min_messages[0]
656+
#else
657+
#define LOG_MIN_MESSAGES_VALUE log_min_messages
658+
#endif
659+
638660
#endif /* SET_USER_COMPAT_H */

include/passcheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
* contains the changes needed by uni_api to load the functionality for
1919
* passcheck.
2020
*/
21-
void passcheck_init();
21+
void passcheck_init(void);

src/clientauth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ clientauth_sighup(SIGNAL_ARGS)
831831
* 3. pgtle.enable_clientauth is ON and no functions are registered with the clientauth feature
832832
*/
833833
static bool
834-
can_allow_without_executing()
834+
can_allow_without_executing(void)
835835
{
836836
List *proc_names;
837837
Oid extOid;
@@ -865,7 +865,7 @@ can_allow_without_executing()
865865
* 2. pgtle.enable_clientauth is REQUIRE and no functions are registered with the clientauth feature
866866
*/
867867
static bool
868-
can_reject_without_executing()
868+
can_reject_without_executing(void)
869869
{
870870
List *proc_names;
871871
Oid extOid;

src/tleextension.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
#include "nodes/plannodes.h"
7474
#include "parser/parse_func.h"
7575
#include "parser/parse_type.h"
76+
#if PG_VERSION_NUM >= 190000
77+
#include "parser/parse_node.h"
78+
#endif
7679
#include "storage/fd.h"
7780
#include "tcop/tcopprot.h"
7881
#include "tcop/utility.h"
@@ -86,6 +89,7 @@
8689
#include "utils/snapmgr.h"
8790
#include "utils/syscache.h"
8891
#include "utils/varlena.h"
92+
#include "utils/tuplestore.h"
8993

9094
#include "constants.h"
9195
#include "tleextension.h"
@@ -1332,7 +1336,7 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
13321336
PGC_USERSET, PGC_S_SESSION,
13331337
GetUserId(),
13341338
GUC_ACTION_SAVE, true, 0, false);
1335-
if (log_min_messages < WARNING)
1339+
if (LOG_MIN_MESSAGES_VALUE < WARNING)
13361340
(void) set_config_option_ext("log_min_messages", "warning",
13371341
PGC_SUSET, PGC_S_SESSION,
13381342
BOOTSTRAP_SUPERUSERID,
@@ -2067,14 +2071,25 @@ CreateExtensionInternal(char *extensionName,
20672071

20682072
if (!OidIsValid(schemaOid))
20692073
{
2074+
#if PG_VERSION_NUM >= 190000
2075+
ParseState *pstate = make_parsestate(NULL);
2076+
#endif
20702077
CreateSchemaStmt *csstmt = makeNode(CreateSchemaStmt);
20712078

2079+
#if PG_VERSION_NUM >= 190000
2080+
pstate->p_sourcetext = "(generated CREATE SCHEMA command)";
2081+
#endif
2082+
20722083
csstmt->schemaname = schemaName;
20732084
csstmt->authrole = NULL; /* will be created by current user */
20742085
csstmt->schemaElts = NIL;
20752086
csstmt->if_not_exists = false;
2087+
#if PG_VERSION_NUM >= 190000
2088+
CreateSchemaCommand(pstate, csstmt, -1, -1);
2089+
#else
20762090
CreateSchemaCommand(csstmt, "(generated CREATE SCHEMA command)",
20772091
-1, -1);
2092+
#endif
20782093

20792094
/*
20802095
* CreateSchemaCommand includes CommandCounterIncrement, so new
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/*
2+
*
3+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/*
7+
* 1. Test that an existing version of an extension cannot be installed again
8+
* 2. Test that a different version of an installed extension can be installed
9+
* 3. Test that CREATE EXTENSION with an explicit version automatically updates
10+
* to that version
11+
* 4. Test that CREATE EXTENSION automatically updates to default version
12+
*/
13+
\pset pager off
14+
CREATE EXTENSION pg_tle;
15+
-- install version 1.0 of an extension
16+
SELECT pgtle.install_extension
17+
(
18+
'test123',
19+
'1.0',
20+
'Test TLE Functions',
21+
$_pgtle_$
22+
CREATE OR REPLACE FUNCTION test123_func()
23+
RETURNS INT AS $$
24+
(
25+
SELECT 42
26+
)$$ LANGUAGE sql;
27+
$_pgtle_$
28+
);
29+
install_extension
30+
-------------------
31+
t
32+
(1 row)
33+
34+
CREATE EXTENSION test123;
35+
SELECT test123_func();
36+
test123_func
37+
--------------
38+
42
39+
(1 row)
40+
41+
DROP EXTENSION test123;
42+
-- an existing version of an extension cannot be installed again
43+
SELECT pgtle.install_extension
44+
(
45+
'test123',
46+
'1.0',
47+
'Test TLE Functions',
48+
$_pgtle_$
49+
CREATE OR REPLACE FUNCTION test123_func()
50+
RETURNS INT AS $$
51+
(
52+
SELECT 21
53+
)$$ LANGUAGE sql;
54+
$_pgtle_$
55+
);
56+
ERROR: extension "test123" already installed
57+
-- but a different version of the same extension can be installed
58+
SELECT pgtle.install_extension
59+
(
60+
'test123',
61+
'1.1',
62+
'Test TLE Functions',
63+
$_pgtle_$
64+
CREATE OR REPLACE FUNCTION test123_func()
65+
RETURNS INT AS $$
66+
(
67+
SELECT 21
68+
)$$ LANGUAGE sql;
69+
CREATE OR REPLACE FUNCTION test123_func_2()
70+
RETURNS INT AS $$
71+
(
72+
SELECT 212121
73+
)$$ LANGUAGE sql;
74+
$_pgtle_$
75+
);
76+
install_extension
77+
-------------------
78+
t
79+
(1 row)
80+
81+
CREATE EXTENSION test123;
82+
SELECT test123_func();
83+
test123_func
84+
--------------
85+
21
86+
(1 row)
87+
88+
SELECT test123_func_2();
89+
test123_func_2
90+
----------------
91+
212121
92+
(1 row)
93+
94+
DROP EXTENSION test123;
95+
-- uninstall version 1.1
96+
SELECT pgtle.set_default_version('test123', '1.0');
97+
set_default_version
98+
---------------------
99+
t
100+
(1 row)
101+
102+
SELECT pgtle.uninstall_extension('test123', '1.1');
103+
uninstall_extension
104+
---------------------
105+
t
106+
(1 row)
107+
108+
CREATE EXTENSION test123;
109+
SELECT test123_func();
110+
test123_func
111+
--------------
112+
42
113+
(1 row)
114+
115+
SELECT test123_func_2(); -- expect to fail
116+
ERROR: function test123_func_2() does not exist
117+
LINE 1: SELECT test123_func_2();
118+
^
119+
DETAIL: There is no function of that name.
120+
DROP EXTENSION test123;
121+
-- create update path to 1.1 instead
122+
SELECT pgtle.install_update_path
123+
(
124+
'test123',
125+
'1.0',
126+
'1.1',
127+
$_pgtle_$
128+
CREATE OR REPLACE FUNCTION test123_func()
129+
RETURNS INT AS $$
130+
(
131+
SELECT 21
132+
)$$ LANGUAGE sql;
133+
CREATE OR REPLACE FUNCTION test123_func_2()
134+
RETURNS INT AS $$
135+
(
136+
SELECT 212121
137+
)$$ LANGUAGE sql;
138+
$_pgtle_$
139+
);
140+
install_update_path
141+
---------------------
142+
t
143+
(1 row)
144+
145+
-- test that CREATE EXTENSION version 1.1 works
146+
CREATE EXTENSION test123 version '1.1';
147+
SELECT test123_func();
148+
test123_func
149+
--------------
150+
21
151+
(1 row)
152+
153+
SELECT test123_func_2();
154+
test123_func_2
155+
----------------
156+
212121
157+
(1 row)
158+
159+
DROP EXTENSION test123;
160+
-- if version 1.1 is set as default, then it should be create-able via the upgrade path
161+
SELECT pgtle.set_default_version('test123', '1.1');
162+
set_default_version
163+
---------------------
164+
t
165+
(1 row)
166+
167+
CREATE EXTENSION test123;
168+
SELECT test123_func();
169+
test123_func
170+
--------------
171+
21
172+
(1 row)
173+
174+
SELECT test123_func_2();
175+
test123_func_2
176+
----------------
177+
212121
178+
(1 row)
179+
180+
DROP EXTENSION test123;
181+
-- sanity check that uninstall works
182+
SELECT pgtle.uninstall_extension('test123');
183+
uninstall_extension
184+
---------------------
185+
t
186+
(1 row)
187+
188+
-- clean up
189+
DROP EXTENSION pg_tle CASCADE;
190+
DROP SCHEMA pgtle;
191+
DROP ROLE pgtle_admin;

0 commit comments

Comments
 (0)