Skip to content

Commit 01f0855

Browse files
author
Antonin Houska
committed
Fixed build for PG 18 and all the supported versions.
1 parent 32c43aa commit 01f0855

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

pg_rewrite.c

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
#include "utils/datum.h"
6565
#include "utils/fmgroids.h"
6666
#include "utils/guc.h"
67+
#if PG_VERSION_NUM >= 170000
6768
#include "utils/injection_point.h"
69+
#endif
6870
#include "utils/lsyscache.h"
6971
#include "utils/memutils.h"
7072
#include "utils/rel.h"
@@ -723,12 +725,13 @@ rewrite_worker_main(Datum main_arg)
723725
relname_dst);
724726
CommitTransactionCommand();
725727

728+
#if PG_VERSION_NUM >= 170000
726729
/*
727730
* In regression tests, use this injection point to check that
728731
* the changes are visible by other transactions.
729732
*/
730733
INJECTION_POINT("pg_rewrite-after-commit");
731-
734+
#endif
732735
}
733736
PG_CATCH();
734737
{
@@ -1018,11 +1021,13 @@ rewrite_table_impl(char *relschema_src, char *relname_src,
10181021
*/
10191022
CommandCounterIncrement();
10201023

1024+
#if PG_VERSION_NUM >= 170000
10211025
/*
10221026
* During testing, wait for another backend to perform concurrent data
10231027
* changes which we will process below.
10241028
*/
10251029
INJECTION_POINT("pg_rewrite-before-lock");
1030+
#endif
10261031

10271032
/*
10281033
* Flush all WAL records inserted so far (possibly except for the last
@@ -2779,11 +2784,11 @@ pg_rewrite_get_task_list(PG_FUNCTION_ARGS)
27792784
isnull = (bool *) palloc0(TASK_LIST_RES_ATTRS * sizeof(bool));
27802785

27812786

2782-
if (strlen(NameStr(task->relschema_src)) > 0)
2783-
values[0] = NameGetDatum(&task->relschema_src);
2787+
if (strlen(NameStr(task->relschema)) > 0)
2788+
values[0] = NameGetDatum(&task->relschema);
27842789
else
27852790
isnull[0] = true;
2786-
values[1] = NameGetDatum(&task->relname_src);
2791+
values[1] = NameGetDatum(&task->relname);
27872792
if (strlen(NameStr(task->relschema_dst)) > 0)
27882793
values[2] = NameGetDatum(&task->relschema_dst);
27892794
else
@@ -2972,7 +2977,9 @@ dump_fk_constraint(HeapTuple tup, Oid relid_dst, const char *relname_dst,
29722977
const char *pkrelname, *pknsp, *fkrelname, *fknsp;
29732978
Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tup);
29742979
Datum val;
2980+
#if PG_VERSION_NUM >= 150000
29752981
bool isnull;
2982+
#endif
29762983
const char *string;
29772984

29782985
Assert(con->contype == CONSTRAINT_FOREIGN);
@@ -3026,8 +3033,18 @@ dump_fk_constraint(HeapTuple tup, Oid relid_dst, const char *relname_dst,
30263033
appendStringInfoString(buf, "FOREIGN KEY (");
30273034

30283035
/* Fetch and build referencing-column list */
3036+
#if PG_VERSION_NUM >= 160000
30293037
val = SysCacheGetAttrNotNull(CONSTROID, tup,
30303038
Anum_pg_constraint_conkey);
3039+
#else
3040+
{
3041+
bool isnull;
3042+
3043+
val = SysCacheGetAttr(CONSTROID, tup, Anum_pg_constraint_conkey,
3044+
&isnull);
3045+
Assert(!isnull);
3046+
}
3047+
#endif
30313048

30323049
decompile_column_index_array(val, con->conrelid, buf);
30333050

@@ -3036,8 +3053,18 @@ dump_fk_constraint(HeapTuple tup, Oid relid_dst, const char *relname_dst,
30363053
quote_qualified_identifier(pknsp, pkrelname));
30373054

30383055
/* Fetch and build referenced-column list */
3056+
#if PG_VERSION_NUM >= 160000
30393057
val = SysCacheGetAttrNotNull(CONSTROID, tup,
30403058
Anum_pg_constraint_confkey);
3059+
#else
3060+
{
3061+
bool isnull;
3062+
3063+
val = SysCacheGetAttr(CONSTROID, tup, Anum_pg_constraint_confkey,
3064+
&isnull);
3065+
Assert(!isnull);
3066+
}
3067+
#endif
30413068

30423069
decompile_column_index_array(val, con->confrelid, buf);
30433070

@@ -3116,6 +3143,7 @@ dump_fk_constraint(HeapTuple tup, Oid relid_dst, const char *relname_dst,
31163143
if (string)
31173144
appendStringInfo(buf, " ON DELETE %s", string);
31183145

3146+
#if PG_VERSION_NUM >= 150000
31193147
/*
31203148
* Add columns specified to SET NULL or SET DEFAULT if
31213149
* provided.
@@ -3128,6 +3156,7 @@ dump_fk_constraint(HeapTuple tup, Oid relid_dst, const char *relname_dst,
31283156
decompile_column_index_array(val, con->conrelid, buf);
31293157
appendStringInfoChar(buf, ')');
31303158
}
3159+
#endif
31313160
}
31323161

31333162
/*
@@ -3151,8 +3180,18 @@ dump_check_constraint(Oid relid_dst, const char *relname_dst, HeapTuple tup,
31513180
dump_constraint_common(nsp, relname_dst, con, buf);
31523181

31533182
/* Fetch constraint expression in parsetree form */
3183+
#if PG_VERSION_NUM >= 160000
31543184
val = SysCacheGetAttrNotNull(CONSTROID, tup,
31553185
Anum_pg_constraint_conbin);
3186+
#else
3187+
{
3188+
bool isnull;
3189+
3190+
val = SysCacheGetAttr(CONSTROID, tup, Anum_pg_constraint_conbin,
3191+
&isnull);
3192+
Assert(!isnull);
3193+
}
3194+
#endif
31563195

31573196
conbin = TextDatumGetCString(val);
31583197
expr = stringToNode(conbin);
@@ -3253,8 +3292,14 @@ decompile_column_index_array(Datum column_index_array, Oid relId,
32533292
int j;
32543293

32553294
/* Extract data from array of int16 */
3295+
#if PG_VERSION_NUM >= 160000
32563296
deconstruct_array_builtin(DatumGetArrayTypeP(column_index_array), INT2OID,
32573297
&keys, NULL, &nKeys);
3298+
#else
3299+
deconstruct_array(DatumGetArrayTypeP(column_index_array), INT2OID,
3300+
sizeof(int16), true, TYPALIGN_SHORT,
3301+
&keys, NULL, &nKeys);
3302+
#endif
32583303

32593304
for (j = 0; j < nKeys; j++)
32603305
{

0 commit comments

Comments
 (0)