Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 143 additions & 13 deletions ci/journey.sh

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions docs/architecture_tiered.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,13 @@ keeps `RETURNING`, a cold one is the anchor `UPDATE` that runs the DuckDB
write. When a statement gives the view no alias, the deparser qualifies its
columns by the view's name, so the retargeted relation takes that name as its
alias; an `UPDATE … FROM`, a `DELETE … USING` and a correlated sub-select
are handled the same way. The hook deparses the statement under ISO dates and
are handled the same way. The hook deparses the statement under ISO dates,
PostgreSQL's verbose interval style, the one interval spelling DuckDB reads
whatever the signs of an interval's fields, so a literal reads the same in
DuckDB whatever the session's `DateStyle` and `IntervalStyle`.
whatever the signs of an interval's fields, and floats at full precision, so a
literal reads the same in DuckDB whatever the session's `DateStyle`,
`IntervalStyle` and `extra_float_digits`. A constant whose PostgreSQL text
DuckDB reads as another value, a `bytea`, a `numeric` with no typmod or an
array, goes in a form that DuckDB reads as the same value.

`COPY <view> FROM` takes the same path. The utility hook reads the rows with
PostgreSQL's `COPY` reader (`BeginCopyFrom`, `NextCopyFrom`), collects
Expand All @@ -477,7 +480,8 @@ the one an application would write and the same rewrite handles it, for a
decoupled view too. `OVERRIDING SYSTEM VALUE` gives the `INSERT` the rule
`COPY` has for a `GENERATED ALWAYS` identity column: a supplied value is kept.
`WHERE` and the options that act after a row is read (`FREEZE`, `ON_ERROR`,
`REJECT_LIMIT`, `DEFAULT`) are refused.
`REJECT_LIMIT`, `DEFAULT`) are refused. The hook writes each literal under the
settings above.

A watermark-split `INSERT` cannot use `RETURNING` - see Cold `RETURNING` under
[Tiered-Specific Limitations](#tiered-specific-limitations).
Expand Down
17 changes: 10 additions & 7 deletions docs/caveats.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ tables:
operator and function on cold or cross-tier reads and in the condition of a
cold write, such as `||`. A hot-only read of the view runs in PostgreSQL
with full jsonb (see [Supported Column Types](supported_types.md)).
- A read through a view, and a cross-tier move of the partition column, run
their statement through pg_duckdb, which renders an interval literal in the
session's `IntervalStyle`. DuckDB reads the `postgres_verbose` style whatever
the signs of an interval's fields, and the `postgres` style unless a positive
field follows a negative one; it refuses the `sql_standard` and `iso_8601`
styles. Set `IntervalStyle` to `postgres_verbose` in a session whose reads or
cross-tier moves spell out such an interval.
- DuckDB gives the values of a `COALESCE`, a `CASE`, a multi-row `VALUES` list
or a `UNION` one decimal type of at most 38 digits. When those values need
more digits before and after the point together, DuckDB rounds a value to
fit; ColdFront refuses only a `numeric` array constant that needs more.
- A read through a view runs its statement through pg_duckdb, which renders an
interval literal in the session's `IntervalStyle`. DuckDB reads the
`postgres_verbose` style whatever the signs of an interval's fields, and the
`postgres` style unless a positive field follows a negative one; it refuses
the `sql_standard` and `iso_8601` styles. Set `IntervalStyle` to
`postgres_verbose` in a session whose reads spell out such an interval.
- Cross-tier isolation differs from PG-native isolation. The cold tier keeps
one Iceberg snapshot for the whole transaction, even at READ COMMITTED, so a
commit by another session after the transaction's first cold read stays
Expand Down
15 changes: 11 additions & 4 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,17 @@ this project adheres to
clustered vector column stores its rows; the statement failed with
`syntax error at or near "VALUE"`. A `COPY` into such a view writes that
clause and failed the same way.
- A `COPY` into a decoupled view loads a vector column, and a decoupled
`INSERT` accepts a vector written as a brace literal, such as `'{0.1,0.2}'`.
Those writes failed with `can't be cast to the destination type FLOAT[]`,
because DuckDB does not read the brace literal of PostgreSQL.
- A cold write and a `COPY` into a decoupled view accept arrays written as
brace literals, such as `'{a,b}'`.
- A `bytea` constant in a cold write stores its bytes.
- A `real` or `double precision` value in a cold write keeps every digit under
any `extra_float_digits`.
- A cross-tier move whose condition or new value spells out an interval runs
under `IntervalStyle = sql_standard`.
- A `MERGE` into a tiered view checks the cutoff on the partition column when
its `INSERT` action writes an `ARRAY[...]` before that column.
- A `numeric` constant in a cold write keeps every digit; a `numeric` array
that needs more than 38 digits is refused.

## [1.0.0-beta4] - 2026-11-17

Expand Down
21 changes: 13 additions & 8 deletions docs/supported_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ array:
writes the array.
- A tiered `INSERT` to the cold tier refuses the array with an error that
names the column.
- A bound parameter in a cold write fails with an error that names no column.
- A bound parameter or a brace literal in a cold write fails with an error
that names no column.
- A write that reads the array from a PostgreSQL table stores the array
renumbered from 1 instead.

Expand All @@ -386,13 +387,17 @@ Spell the array type of a decoupled table as the element type followed by
tiered table, because duckdb-iceberg does not add a nested column to an
Iceberg table.

A tiered `INSERT` accepts an array in any spelling, because the source of the
statement runs in PostgreSQL. A cold `UPDATE` and a decoupled `INSERT` run in
DuckDB, which does not read the brace literal of PostgreSQL. A `'{a,b}'`
literal reaches DuckDB as text and fails to cast. Write the array as
`ARRAY['a', 'b']`, or pass the array as a bound parameter. A `real[]` brace
literal is the exception, because a `COPY` into a view writes a vector that
way; ColdFront rewrites a `real[]` literal into a form that DuckDB reads.
A write accepts an array as an `ARRAY[...]` constructor, as a brace literal
such as `'{a,b}'`, or as a bound parameter. A tiered `INSERT` runs the source
of the statement in PostgreSQL. A cold `UPDATE` and a decoupled `INSERT` run
in DuckDB, which does not read the brace literal of PostgreSQL. ColdFront
therefore rewrites a brace literal in such a write into a form that DuckDB
reads. A `COPY` into a decoupled view writes every array as a brace literal,
which ColdFront rewrites the same way. ColdFront refuses a `numeric` array
constant, as a brace literal or `ARRAY[...]`, whose elements need more than 38
digits together, because DuckDB would round an element to fit one decimal
type. A `COPY` into a tiered view is a tiered
`INSERT`, so PostgreSQL reads the brace literal.

Reads through a view run in DuckDB once the table has a cold tier. The
following array operations work in such a read:
Expand Down
18 changes: 15 additions & 3 deletions extension/coldfront/coldfront--1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,12 @@ $$;
-- raw_query runs; hot→cold rows are serialised from a heap cursor. DELETE is by
-- the OLD primary key; old/new keys differ (the partition column changed) so it
-- never hits a just-inserted row.
--
-- pg_duckdb deparses a read of the cold rows, constants included, under the
-- session's settings, so the two reads run under the ones deparse_flat writes
-- for DuckDB: ISO dates, verbose intervals and floats at full precision. The
-- statements PostgreSQL runs on the caller's expressions come before and after
-- them, under the caller's settings, which v_caller holds.
CREATE FUNCTION coldfront._cross_tier_move(
p_view_schema text, p_view_name text, p_where text, p_newpc text, p_cold_where text
) RETURNS void
Expand Down Expand Up @@ -1282,6 +1288,8 @@ DECLARE
v_targets timestamptz[];
v_hot_targets timestamptz[];
v_uncovered bigint;
v_caller text[] := ARRAY[current_setting('DateStyle'), current_setting('IntervalStyle'),
current_setting('extra_float_digits')];
BEGIN
-- The hook rewrite that reaches here is a bare SELECT, which PG's read-only
-- check passes, and the heap legs below run before the cold write's own
Expand Down Expand Up @@ -1362,12 +1370,14 @@ BEGIN
-- one never mixes the DuckDB read with pg_catalog (which pg_duckdb cannot
-- read), then check coverage against pg_inherits leaf bounds (split_part on the
-- single-key FOR VALUES FROM ('lo') TO ('hi') rendering; no regex).
EXECUTE format(
'SELECT array_agg(DISTINCT (%2$s)::timestamptz) FROM ( %1$s ) s WHERE (%3$s) AND (%2$s) >= %4$s',
v_inner, p_newpc, p_cold_where, v_cut_lit) INTO v_targets;
EXECUTE format(
'SELECT array_agg(DISTINCT (%6$s)::timestamptz) FROM %1$I.%2$I WHERE (%5$s) AND %3$s >= %4$s AND (%6$s) >= %4$s',
v_hot_schema, v_hot_relname, v_pc, v_cut_lit, p_where, p_newpc) INTO v_hot_targets;
PERFORM set_config('DateStyle', 'ISO, YMD', true), set_config('IntervalStyle', 'postgres_verbose', true),
set_config('extra_float_digits', '3', true);
EXECUTE format(
'SELECT array_agg(DISTINCT (%2$s)::timestamptz) FROM ( %1$s ) s WHERE (%3$s) AND (%2$s) >= %4$s',
v_inner, p_newpc, p_cold_where, v_cut_lit) INTO v_targets;
v_targets := COALESCE(v_targets, '{}'::timestamptz[]) || COALESCE(v_hot_targets, '{}'::timestamptz[]);
IF array_length(v_targets, 1) > 0 THEN
SELECT count(*) INTO v_uncovered
Expand Down Expand Up @@ -1422,6 +1432,8 @@ BEGIN
END IF;
END LOOP;
CLOSE cur;
PERFORM set_config('DateStyle', v_caller[1], true), set_config('IntervalStyle', v_caller[2], true),
set_config('extra_float_digits', v_caller[3], true);

-- hot→cold: remove the crossing rows from the heap and capture them for the
-- Iceberg insert in ONE atomic DELETE ... RETURNING, so there is no
Expand Down
Loading