From 7febff7d0f4121e528b33777a826d407047b5f17 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Mon, 10 Nov 2025 06:01:37 +0530 Subject: [PATCH 1/2] Update CI --- .cargo/config.toml | 5 +++++ .github/workflows/ci.yml | 11 ++++------- .github/workflows/release.yml | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 13c456b..daaf7a3 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,8 @@ +[alias] +format = "fmt" +format-check = "fmt --check" +lint = "clippy --all-targets --all-features -- -D warnings" + [target.'cfg(target_os="macos")'] # Postgres symbols won't be available until runtime rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 694de8f..4e9153c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,23 +36,20 @@ jobs: name: Linting (fmt + clippy) runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@v4 - name: Install rust uses: dtolnay/rust-toolchain@1.85.0 with: components: rustfmt, clippy - - name: Checkout - uses: actions/checkout@v3 - name: Format check - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check + run: cargo format-check lockfile: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install rust uses: dtolnay/rust-toolchain@1.85.0 - name: Lockfile check diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 22ab601..b6680b6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -40,7 +40,7 @@ jobs: timeout-minutes: 45 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install rust uses: dtolnay/rust-toolchain@1.85.0 - name: Install dependencies From 234bda80599f16f213639a43b60e9d3a190842a5 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Mon, 10 Nov 2025 06:12:50 +0530 Subject: [PATCH 2/2] Add ulid_to_timestamptz cast --- src/lib.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 80578b6..b160c17 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,6 @@ use core::ffi::CStr; +use std::time::{Duration, SystemTime}; + use inner_ulid::Ulid as InnerUlid; use pg_sys::Datum as SysDatum; use pgrx::callconv::{ArgAbi, BoxRet}; @@ -7,7 +9,6 @@ use pgrx::{ pg_shmem_init, pg_sys::Oid, prelude::*, rust_regtypein, PgLwLock, PgSharedMemoryInitialization, StringInfo, Uuid, }; -use std::time::{Duration, SystemTime}; ::pgrx::pg_module_magic!(); @@ -141,8 +142,7 @@ fn ulid_to_bytea(input: ulid) -> Vec { #[pg_extern(immutable, parallel_safe)] fn ulid_to_timestamp(input: ulid) -> Timestamp { - let inner_seconds = (InnerUlid(input.0).timestamp_ms() as f64) / 1000.0; - to_timestamp(inner_seconds).into() + ulid_to_timestamptz(input).into() } #[pg_extern(immutable, parallel_safe)] @@ -160,6 +160,12 @@ fn timestamp_to_ulid(input: Timestamp) -> ulid { ulid(inner.0) } +#[pg_extern(immutable, parallel_safe)] +fn ulid_to_timestamptz(input: ulid) -> TimestampWithTimeZone { + let inner_seconds = (InnerUlid(input.0).timestamp_ms() as f64) / 1000.0; + to_timestamp(inner_seconds) +} + #[pg_extern(immutable, parallel_safe)] fn timestamptz_to_ulid(input: TimestampWithTimeZone) -> ulid { let epoch: f64 = input @@ -182,6 +188,7 @@ CREATE CAST (ulid AS uuid) WITH FUNCTION ulid_to_uuid(ulid) AS IMPLICIT; CREATE CAST (ulid AS bytea) WITH FUNCTION ulid_to_bytea(ulid) AS IMPLICIT; CREATE CAST (ulid AS timestamp) WITH FUNCTION ulid_to_timestamp(ulid) AS IMPLICIT; CREATE CAST (timestamp AS ulid) WITH FUNCTION timestamp_to_ulid(timestamp) AS IMPLICIT; +CREATE CAST (ulid AS timestamptz) WITH FUNCTION ulid_to_timestamptz(ulid) AS IMPLICIT; CREATE CAST (timestamptz AS ulid) WITH FUNCTION timestamptz_to_ulid(timestamptz) AS IMPLICIT; "#, name = "ulid_casts", @@ -191,6 +198,7 @@ CREATE CAST (timestamptz AS ulid) WITH FUNCTION timestamptz_to_ulid(timestamptz) ulid_to_bytea, ulid_to_timestamp, timestamp_to_ulid, + ulid_to_timestamptz, timestamptz_to_ulid ] ); @@ -207,6 +215,7 @@ mod tests { 1, 134, 203, 101, 37, 215, 129, 218, 129, 92, 126, 37, 166, 191, 231, 219, ]; const TIMESTAMP: &str = "2023-03-10 12:00:49.111"; + const TIMESTAMPTZ: &str = "2023-03-10 12:00:49.111+00"; #[pg_test] fn test_null_to_ulid() { @@ -262,6 +271,15 @@ mod tests { assert_eq!(Some("01GV5PA9EQ0000000000000000"), result); } + #[pg_test] + fn test_ulid_to_timestamptz() { + let result = Spi::get_one::<&str>(&format!( + "SET TIMEZONE TO 'UTC'; SELECT '{TEXT}'::ulid::timestamptz::text;" + )) + .unwrap(); + assert_eq!(Some(TIMESTAMPTZ), result); + } + #[pg_test] fn test_timestamptz_to_ulid() { let result = Spi::get_one::<&str>(&format!(