Skip to content

Commit 213a3d7

Browse files
authored
Support PG18 beta1 (#788)
This allows compiling with PG18 beta1, we might need to do more changes before the actual release.
1 parent f42b4b0 commit 213a3d7

18 files changed

+13857
-28
lines changed

.github/workflows/build_and_test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ jobs:
5252
type: ReleaseStatic
5353
- version: REL_17_STABLE
5454
type: Debug
55+
- version: REL_18_BETA1
56+
type: Release
5557

5658
# Not enabled for now (waiting for April 2025 code freeze)
5759
# - version: master

Makefile.global

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ $(error Minimum version of PostgreSQL required is $(PG_MIN_VER) (but have $(PG_V
77
endif
88

99
# If you want to test with an unsupported PG version you can pass a different value to make
10-
PG_MAX_VER ?= 17
10+
PG_MAX_VER ?= 18
1111
ifeq ($(shell expr "$(PG_MAX_VER)" \>= "$(PG_VER)"), 0)
1212
$(error Maximum supported version of PostgreSQL is $(PG_MAX_VER) (but have $(PG_VER)))
1313
endif

include/pgduckdb/pg/declarations.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,6 @@ struct Plan;
9090
struct FuncExpr;
9191

9292
typedef struct FunctionCallInfoBaseData *FunctionCallInfo;
93+
94+
struct ExplainState;
9395
}

include/pgduckdb/pg/explain.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "pgduckdb/pg/declarations.hpp"
2+
#include "duckdb/common/enums/explain_format.hpp"
3+
4+
namespace pgduckdb::pg {
5+
void ExplainPropertyText(const char *qlabel, const char *value, ExplainState *es);
6+
7+
duckdb::ExplainFormat DuckdbExplainFormat(ExplainState *es);
8+
9+
bool IsExplainAnalyze(ExplainState *es);
10+
} // namespace pgduckdb::pg

include/pgduckdb/pg/locale.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "pgduckdb/pg/declarations.hpp"
2+
3+
namespace pgduckdb::pg {
4+
bool IsCLocale(Oid collation_id);
5+
}

include/pgduckdb/vendor/pg_ruleutils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ extern List *pgduckdb_set_deparse_context_plan(List *dpcontext,
4343
struct Plan *plan, List *ancestors);
4444
extern List *pgduckdb_select_rtable_names_for_explain(List *rtable,
4545
Bitmapset *rels_used);
46+
#if PG_VERSION_NUM >= 180000
47+
extern char *get_window_frame_options_for_explain(int frameOptions,
48+
Node *startOffset,
49+
Node *endOffset,
50+
List *dpcontext,
51+
bool forceprefix);
52+
#endif
4653
extern char *pgduckdb_generate_collation_name(Oid collid);
4754
extern char *pgduckdb_generate_opclass_name(Oid opclass);
4855
extern char *pgduckdb_get_range_partbound_string(List *bound_datums);

src/pg/explain.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "pgduckdb/pg/explain.hpp"
2+
#include "pgduckdb/pgduckdb_utils.hpp"
3+
4+
extern "C" {
5+
#include "postgres.h"
6+
7+
#if PG_VERSION_NUM >= 180000
8+
#include "commands/explain_format.h"
9+
#include "commands/explain_state.h"
10+
#else
11+
#include "commands/explain.h"
12+
#endif
13+
}
14+
15+
namespace pgduckdb::pg {
16+
void
17+
ExplainPropertyText(const char *qlabel, const char *value, ExplainState *es) {
18+
PostgresFunctionGuard(::ExplainPropertyText, qlabel, value, es);
19+
}
20+
21+
duckdb::ExplainFormat
22+
DuckdbExplainFormat(ExplainState *es) {
23+
if (es->format == EXPLAIN_FORMAT_JSON)
24+
return duckdb::ExplainFormat::JSON;
25+
26+
return duckdb::ExplainFormat::DEFAULT;
27+
}
28+
29+
bool
30+
IsExplainAnalyze(ExplainState *es) {
31+
return es->analyze;
32+
}
33+
} // namespace pgduckdb::pg

src/pg/locale.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "pgduckdb/pg/locale.hpp"
2+
3+
extern "C" {
4+
#include "postgres.h"
5+
}
6+
7+
/*
8+
* Needs to be done outside of 'extern "C"' block AND before including
9+
* pg_locale.h. Otherwise you get many compilation errors about templates being
10+
* used in C linkage. It also needs to be done after including postgres.h,
11+
* because otherwise USE_ICU does not exist.
12+
*/
13+
#ifdef USE_ICU
14+
#include <unicode/ucol.h>
15+
#endif
16+
17+
extern "C" {
18+
#include "utils/pg_locale.h"
19+
}
20+
21+
namespace pgduckdb::pg {
22+
23+
bool
24+
IsCLocale(Oid collation_id) {
25+
#if PG_VERSION_NUM >= 180000
26+
return pg_newlocale_from_collation(collation_id)->collate_is_c;
27+
#else
28+
return lc_ctype_is_c(collation_id);
29+
#endif
30+
}
31+
32+
} // namespace pgduckdb::pg

src/pg/relations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ GetAttName(const Form_pg_attribute att) {
5656

5757
Form_pg_attribute
5858
GetAttr(const TupleDesc tupleDesc, int i) {
59-
return &tupleDesc->attrs[i];
59+
return TupleDescAttr(tupleDesc, i);
6060
}
6161

6262
bool

src/pgduckdb.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ extern "C" {
1313
#include "pgduckdb/pgduckdb_xact.hpp"
1414

1515
extern "C" {
16+
17+
#ifdef PG_MODULE_MAGIC_EXT
18+
PG_MODULE_MAGIC_EXT(.name = "pg_duckdb", .version = "1.0.0");
19+
#else
1620
PG_MODULE_MAGIC;
21+
#endif
1722

1823
void
1924
_PG_init(void) {

0 commit comments

Comments
 (0)