Skip to content

Commit

Permalink
Ensure PostgreSQL 16 compatibility
Browse files Browse the repository at this point in the history
DateTimeParseError: PostgreSQL source code documents that we can pass
null pointers here:

 > extra can be NULL if not needed for the particular dterr value.
 > [...]
 > If escontext points to an ErrorSaveContext node, that is filled instead
 > of throwing an error

DecodeDateTime however does not allow us to pass a null pointer, reading
the source code, it is expected that extra is not null. Therefore, in
order for us to get this thing to compile, we create an empty
DateTimeErrorExtra, which gets passed along.
  • Loading branch information
feikesteenbergen committed Oct 4, 2023
1 parent 75cb639 commit 8da9de7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ hop on the [Discussions forum](https://github.com/timescale/timescaledb-toolkit/

See above for prerequisites and installation instructions.

You can run tests against a postgres version `pg12`, `pg13`, `pg14`, or `pg15` using
You can run tests against a postgres version `pg12`, `pg13`, `pg14`, `pg15` or `pg16` using

```
cargo pgrx test ${postgres_version}
Expand Down
3 changes: 2 additions & 1 deletion extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ edition = "2021"
crate-type = ["cdylib"]

[features]
default = ["pg14"]
default = ["pg16"]
pg12 = ["pgrx/pg12", "pgrx-tests/pg12"]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
pg_test = ["approx"]

[dependencies]
Expand Down
43 changes: 42 additions & 1 deletion extension/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
os::raw::{c_char, c_int},
};

use pgrx::pg_sys;
use pgrx::pg_sys::{self, DateTimeErrorExtra};
use std::ffi::CStr;

pub(crate) mod collations;
Expand Down Expand Up @@ -75,6 +75,13 @@ pub extern "C" fn _ts_toolkit_decode_timestamptz(text: &str) -> i64 {
pg_sys::MAXDATEFIELDS as i32,
&mut nf,
);
#[cfg(any(
feature = "pg11",
feature = "pg12",
feature = "pg13",
feature = "pg14",
feature = "pg15"
))]
if dterr == 0 {
dterr = pg_sys::DecodeDateTime(
field.as_mut_ptr(),
Expand All @@ -86,11 +93,45 @@ pub extern "C" fn _ts_toolkit_decode_timestamptz(text: &str) -> i64 {
&mut tz,
)
}
#[cfg(feature = "pg16")]
if dterr == 0 {
let mut extra = DateTimeErrorExtra::default();
dterr = pg_sys::DecodeDateTime(
field.as_mut_ptr(),
ftype.as_mut_ptr(),
nf,
&mut dtype,
tm,
&mut fsec,
&mut tz,
&mut extra as *mut DateTimeErrorExtra
)
}

#[cfg(any(
feature = "pg11",
feature = "pg12",
feature = "pg13",
feature = "pg14",
feature = "pg15"
))]
if dterr != 0 {
pg_sys::DateTimeParseError(
dterr,
str.as_ptr(),
b"timestamptz\0".as_ptr().cast::<c_char>(),
str.as_ptr(),
str.as_ptr(),
);
}
#[cfg(feature = "pg16")]
if dterr != 0 {
pg_sys::DateTimeParseError(
dterr,
core::ptr::null_mut(),
str.as_ptr(),
b"timestamptz\0".as_ptr().cast::<c_char>(),
core::ptr::null_mut(),
);
}

Expand Down
2 changes: 1 addition & 1 deletion tools/build
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ usage() {
}

require_pg_version() {
[ -n "$pg_version" ] || die 'specify one of -pg12 | -pg13 | -pg14 | -pg15'
[ -n "$pg_version" ] || die 'specify one of -pg12 | -pg13 | -pg14 | -pg15 | -pg16'
}

find_pg_config() {
Expand Down

0 comments on commit 8da9de7

Please sign in to comment.