SET timezone = 'UTC'; -- fractional digits: 1..9 digits, trailing zeros beyond 9 allowed, nonzero 10th digit rejected SELECT '2024-01-01 00:00:00.1 UTC'::nanotimestamptz, '2024-01-01 00:00:00.123456789 UTC'::nanotimestamptz; nanotimestamptz | nanotimestamptz ----------------------------------+---------------------------------- 2024-01-01 00:00:00.100000000+00 | 2024-01-01 00:00:00.123456789+00 (1 row) SELECT '2024-01-01 00:00:00.1234567890 UTC'::nanotimestamptz; nanotimestamptz ---------------------------------- 2024-01-01 00:00:00.123456789+00 (1 row) SELECT '2024-01-01 00:00:00.1234567891 UTC'::nanotimestamptz; ERROR: more than 9 fractional second digits in "2024-01-01 00:00:00.1234567891 UTC" LINE 1: SELECT '2024-01-01 00:00:00.1234567891 UTC'::nanotimestamptz... ^ -- ISO 8601 forms SELECT '2024-06-30T12:00:00.000000001Z'::nanotimestamptz, '2024-06-30T12:00:00.5+05:30'::nanotimestamptz; nanotimestamptz | nanotimestamptz ----------------------------------+---------------------------------- 2024-06-30 12:00:00.000000001+00 | 2024-06-30 06:30:00.500000000+00 (1 row) SELECT 'garbage'::nanotimestamptz; ERROR: invalid input syntax for type timestamp with time zone: "garbage" LINE 1: SELECT 'garbage'::nanotimestamptz; ^ SELECT 'infinity'::nanotimestamptz; ERROR: infinite timestamps are not supported by nanotimestamptz LINE 1: SELECT 'infinity'::nanotimestamptz; ^ -- output follows the session time zone, like timestamptz SET timezone = 'Asia/Taipei'; SELECT '2024-01-01 00:00:00.123456789 UTC'::nanotimestamptz; nanotimestamptz ---------------------------------- 2024-01-01 08:00:00.123456789+08 (1 row) SELECT '2024-01-01 00:00:00.123456789'::nanotimestamptz; nanotimestamptz ---------------------------------- 2024-01-01 00:00:00.123456789+08 (1 row) SET timezone = 'America/New_York'; SELECT '2024-07-01 12:00:00.000000001 UTC'::nanotimestamptz, '2024-07-01 12:00:00 UTC'::timestamptz; nanotimestamptz | timestamptz ----------------------------------+------------------------------ 2024-07-01 08:00:00.000000001-04 | Mon Jul 01 08:00:00 2024 EDT (1 row) SET timezone = 'Asia/Kolkata'; SELECT '2024-01-01 00:00:00.000000001 UTC'::nanotimestamptz, '2024-01-01 00:00:00 UTC'::timestamptz; nanotimestamptz | timestamptz -------------------------------------+------------------------------ 2024-01-01 05:30:00.000000001+05:30 | Mon Jan 01 05:30:00 2024 IST (1 row) -- output equals timestamptz output when there are no sub-microsecond digits SET timezone = 'Europe/Amsterdam'; SET DateStyle = 'ISO, YMD'; SELECT x::text = regexp_replace(x::timestamptz::text, '^(.* \d\d:\d\d:\d\d)([+-])', '\1.000000000\2') FROM (VALUES ('2024-03-31 02:30:00 UTC'::nanotimestamptz), ('1950-06-01 10:00:00 UTC'), ('2100-10-31 00:59:59 UTC')) v(x); ?column? ---------- t t t (3 rows) RESET DateStyle; SET timezone = 'UTC'; -- negative values print unambiguously (prototype bug fixed) SELECT (-1)::bigint::nanotimestamptz, (-1000000001)::bigint::nanotimestamptz; nanotimestamptz | nanotimestamptz ----------------------------------+---------------------------------- 1969-12-31 23:59:59.999999999+00 | 1969-12-31 23:59:58.999999999+00 (1 row) -- text round trip SELECT t::text::nanotimestamptz = t FROM (VALUES ('4714-11-24 00:00:00 UTC BC'::nanotimestamptz), ('1969-12-31 23:59:59.999999999 UTC'), ('294276-12-31 23:59:59.999999999 UTC')) v(t); ?column? ---------- t t t (3 rows) -- binary send/recv round trip through COPY CREATE TEMP TABLE bin_src(t nanotimestamptz); INSERT INTO bin_src VALUES ('4714-11-24 00:00:00 UTC BC'), ('1969-12-31 23:59:59.999999999 UTC'), ('2024-01-01 00:00:00.123456789 UTC'), ('294276-12-31 23:59:59.999999999 UTC'); SELECT nanotimestamptz_send(t) FROM bin_src; nanotimestamptz_send ------------------------------------ \xffffffcee75bee000000000000000000 \xffffffffffffffff000000003b9ac9ff \x000000006592008000000000075bcd15 \x00000863b432d9ff000000003b9ac9ff (4 rows) -- per-port file name so several servers (different OS users) can run the suite SELECT '/tmp/pg_nanotime_regress_' || current_setting('port') || '.bin' AS binfile \gset COPY bin_src TO :'binfile' WITH (FORMAT binary); CREATE TEMP TABLE bin_dst(t nanotimestamptz); COPY bin_dst FROM :'binfile' WITH (FORMAT binary); SELECT count(*) FROM bin_src s JOIN bin_dst d ON s.t = d.t; count ------- 4 (1 row)