SQL and clients
Dialect
Section titled “Dialect”Igloo speaks the PostgreSQL wire protocol, but queries run on DuckDB, so the
SQL dialect is DuckDB’s,
which is close to PostgreSQL’s. Everyday SQL (joins, window functions, CTEs,
aggregates, GROUP BY ALL, QUALIFY) works as written; DuckDB’s function
library applies.
A session can choose Snowflake’s dialect instead, with
SET sql_dialect = 'snowflake', a connection option or a role setting:
Igloo then translates Snowflake SQL (IFF, DATEADD, v:path::type,
FLATTEN and the rest) to DuckDB’s before it checks and runs it.
Sketches for deduplicated reach, geometry and H3 functions, and DuckDB’s approximate and statistical functions are described in media analytics.
approx_count_distinct(x) counts as APPROX_COUNT_DISTINCT does in
Snowflake’s dialect, with DataSketches’ HyperLogLog of
4,096 registers: within about 1.6%, as Snowflake, and exactly up to about
300 values. DuckDB’s own has 64 registers and errs by about 13%. It counted
a column of 6 categories as 5 and one of 1,000 values as 1,249, where Igloo
counts 6 and 1,020, and was off by 15% on average over 40 columns of 100,000
values, where Igloo is off by 1.8%. In a SELECT with GROUP BY and as a
window function it counts exactly, as count(DISTINCT x). A call keeps
DuckDB’s estimate in a select item without an alias that is more than the
call of a column, since DuckDB names the column after the item, and with an
ORDER BY, a parameter or a volatile function inside it.
COUNT(*) OVER (), the number of rows of the result beside each row (as in
a table preview), makes DuckDB hold every row before it returns the first.
Where it is the number of rows the FROM and WHERE produce, Igloo counts
those once instead, as (SELECT count(*) FROM ... WHERE ...), in either
dialect: in a SELECT without GROUP BY, aggregates, DISTINCT,
QUALIFY or another window function, whose other items are columns,
constants and operators, and whose FROM, WHERE and common table
expressions read the same rows each time (no sample, LIMIT, window
function, random() or parameter). Previewing 50 rows of a table of 37
million rows with its row count takes 1 s instead of 8.
A statement that repeats a subquery in FROM, as generated reports do when
they take a top 10 and a bottom 5 of the same report, has DuckDB compute the
subquery once per copy. Igloo computes it once, in either dialect, as a
common table expression marked MATERIALIZED (named _igloo_shared_1, …,
as EXPLAIN shows) that the copies read. Copies compare ignoring case
outside literals and quoted names, white space and comments. A subquery
stays as written when computing it once could change what a copy reads or
shows: when it calls a volatile function (random(), uuid(),
nextval(), or a macro that calls one) or samples, names a common table
expression defined outside it, refers to the columns of the query around it,
or is read by a SELECT that neither sorts nor groups its rows again or has
a window function (a materialized subquery does not keep its rows’ order),
and in statements with ? parameters. Checks, policies and grants apply to
the statement as it runs; query history shows it as sent. A report that
selected twice from one subquery of 17 common table expressions took 597 s
on an 8-core machine and takes 128 s.
Three or more common table expressions of one WITH that each group the
same rows the same way, as reports write to count one join several ways (a
SELECT DISTINCT id, x, a count(DISTINCT day) by id, x and a count(*)
by id, x, all over the same FROM and WHERE), have DuckDB scan, join and
group those rows once for each. Igloo groups them once, in either dialect, in
a common table expression marked MATERIALIZED (named _igloo_siblings_1,
…) with every aggregate they ask for, and each reads its columns from it.
It does so where each is SELECT [DISTINCT] ... FROM ... [WHERE ...] [GROUP BY ...] and nothing else, with the same FROM and WHERE (compared as
shared subqueries are) and the same groups, selects only its groups and
count, sum, min, max and avg calls (no FILTER or OVER), names
every column, and calls no volatile function. Keeping the groups costs about
one grouping, so two stay as written. A report of two sets of three over 40
million rows took 110 CPU-seconds rather than 224, and 11 s rather than 40 on
16 cores.
A UNION ALL whose branches select from the same rows, as reports write to
compare several measures of one audience (SELECT v.id, 'email' AS channel, ... FROM v JOIN g ON g.id = v.id UNION ALL SELECT v.id, 'video', ... FROM v JOIN g ON g.id = v.id ...), has DuckDB scan and join once per
branch. When such a union is a subquery in the FROM of a SELECT that
groups or aggregates its rows, Igloo computes the shared FROM and WHERE
once instead, in either dialect, and makes each of their rows once per
branch (CROSS JOIN range(n) AS _igloo_branches(_igloo_branch)), each
column that differs between branches a CASE on the branch. The union stays
as written unless its branches have the same FROM and WHERE and select
only columns, constants and operators (no functions, subqueries,
DISTINCT, GROUP BY or LIMIT); every column that differs has a name in
the first branch; the FROM and WHERE read the same rows each time (no
sample, LIMIT, window function, volatile function or parameter); the
SELECT that reads the union has no window function or aggregate that
depends on the order of its rows (list, string_agg, first, …); and
DuckDB describes the factored rows with the union’s column names and types.
A report of 16 such branches over 40 million rows took 45 to 99 s on one
machine and takes 2.3 to 2.6 s; over 100 million, 177 s and 4.7 s.
Tables live in the Iceberg catalog, named lake in SQL (IGLOO_CATALOG_NAME),
and the default schema is public. Unqualified names resolve to
lake.public, so events and lake.public.events are the same table.
Connections to PostgreSQL, MySQL and
Snowflake databases are catalogs of their own, such as
crm.public.customers.
Tables
Section titled “Tables”| Statement | Supported |
|---|---|
CREATE TABLE, CREATE TABLE AS SELECT |
Yes |
INSERT, INSERT …, INSERT …, MERGE INTO |
Yes |
UPDATE, DELETE |
Yes |
DROP TABLE, CREATE SCHEMA, DROP SCHEMA |
Yes; DROP TABLE … drops only the table, DROP SCHEMA … what is in the schema, see below |
ALTER TABLE …, ADD COLUMN, DROP COLUMN |
Yes |
CREATE OR REPLACE TABLE |
Yes; see below |
CREATE [OR REPLACE] VIEW, DROP VIEW, ALTER VIEW … |
Yes; see views |
COMMENT ON SCHEMA, TABLE, VIEW, COLUMN |
Yes; see comments |
ALTER TABLE, VIEW, SCHEMA … |
Yes; see the catalog |
CREATE TEMP TABLE, CREATE TEMP VIEW |
Yes; held in memory for the session only |
COPY INTO table FROM 'location' |
Yes, outside transactions; see loading |
COPY table [(columns)] FROM STDIN |
Yes, in text, CSV and binary; see loading |
CREATE [OR REPLACE] MATERIALIZED VIEW, REFRESH MATERIALIZED VIEW |
Yes, outside transactions; see materialized views |
CREATE [OR REPLACE] DYNAMIC TABLE, ALTER DYNAMIC TABLE … |
Yes, outside transactions; see dynamic tables |
CREATE [OR REPLACE] TABLE …, CREATE [OR REPLACE] SCHEMA … |
Yes, outside transactions; see clones |
ALTER TABLE …, CREATE TAG, DROP BRANCH, DROP TAG, FAST FORWARD |
Yes, outside transactions; see branches and tags |
ALTER TABLE …, RESET SORTED BY |
Yes, outside transactions; see sort orders |
CREATE TABLE …, ALTER TABLE …, RESET PARTITIONED BY |
Yes; see bucketed tables |
CREATE TASK, CREATE PIPE |
Yes; see tasks and pipes |
PRIMARY KEY, UNIQUE |
Accepted but not enforced |
NOT NULL |
Enforced |
CREATE OR REPLACE TABLE writes the new table under a temporary name, then
drops the old table and renames the new one into place. A failure while
writing leaves the old table as it was. The swap is quick but not atomic: a
query that starts in the instant between drop and rename finds no table.
When the catalog fails during the swap, Igloo asks it what the drop or
rename did before going on, and once the old table may be gone it never
drops the new one. If the catalog cannot say (SQLSTATE 40003, for one), the
statement fails with an error that names the temporary table holding the
new data, name__igloo_new_..., and the ALTER TABLE ... RENAME TO that
puts it in place.
The catalog records nothing that depends on a table, so DROP TABLE ... CASCADE drops just the table, like DROP TABLE: views that read it fail
when they are next queried. A dropped table’s files are deleted with it,
as are those of a table CREATE OR REPLACE TABLE replaces, ... CLONE
included, unless clones read them. What a drop leaves,
erasure requests delete (privacy).
A dropped table cannot be restored.
DROP SCHEMA ... CASCADE drops what the schema holds, one object at a time,
each as its own DROP would: its materialized views and dynamic tables with
their tables and state, its views, and its tables, whose files go as DROP TABLE’s do; then the schema. Before it drops anything it checks that the
user may drop all of it (a materialized view only its owner or an admin
may drop). Something refused after that, as a table an erasure request is
erasing from, stops it there, and the error names it; what came before it
is dropped. Without CASCADE, a schema that holds anything is kept.
Sort orders and clustering
Section titled “Sort orders and clustering”A table’s sort order, its clustering key, says how its rows should be ordered in its files. Table maintenance clusters a table that has one: it rewrites the files whose ranges of the key’s first column overlap, sorted, so a filter on that column, such as a customer’s id, reads a few files instead of all of them. Writes stay as fast as before; their files are clustered on the next maintenance pass.
ALTER TABLE lake.public.visits SET SORTED BY (customer_id, day DESC);ALTER TABLE lake.public.visits RESET SORTED BY; -- no key againSELECT table_name, clustering_key FROM igloo.tables; -- LINEAR(customer_id, day DESC)- Igloo keeps the key in the table property
igloo.clustering-key(the fields of an Iceberg sort order, as JSON), not as the table’s default Iceberg sort order: DuckDB, which writes Igloo’s tables, cannot insert into, update or merge into a table with an Iceberg sort order.igloo.tables,information_schema.tables(clustering_key) andSHOW OBJECTS(cluster_by) show the key as Snowflake shows one. - A table another engine gave an Iceberg sort order is clustered by it, but
Igloo cannot write to it:
INSERT,UPDATEandMERGEfail and say so.SET SORTED BY(with the same columns, to keep the order) orRESET SORTED BYmoves the order out of the table’s Iceberg metadata, after which Igloo writes to it. - Each column takes
ASC(the default) orDESC, andNULLS FIRSTorNULLS LAST(by default first when ascending, last when descending). Columns must be top-level columns of a primitive type: not lists, maps or structs. Setting the order a table already has changes nothing. - It needs what
ALTER TABLEneeds: the writer role orCREATEon the table’s schema. It runs outside transaction blocks, on its own in a query of several statements, and only on tables of the Iceberg catalog (not views or temporary tables). - In Snowflake’s dialect,
CLUSTER BY (a, b)onCREATE TABLEorALTER TABLE, andALTER TABLE ... DROP CLUSTERING KEY, set and reset it; see Snowflake SQL. SELECT SYSTEM$CLUSTERING_DEPTH('lake.public.visits'), in either dialect, returns how deep the table’s files stack by its key’s first column, from its manifests: 1 when no two files overlap (see clustering).SYSTEM$CLUSTERING_DEPTH('t', '(column)')measures by a column instead, as for a table without a key. It needsSELECTon the table and runs on its own.
Bucketed tables
Section titled “Bucketed tables”A table partitioned by the bucket transform of a column, bucket(n, column), keeps the rows of each bucket of the column’s hash in files of
their own, as Iceberg’s spec has every engine write them. Workers then join
two such tables on their bucketed columns, group by the column or count its
distinct values bucket by bucket, each reading the same buckets of every
table, without exchanging rows first, and write what they join such a table
to on that column into its buckets, leaving the table in place (see bucketed
tables):
CREATE TABLE lake.public.orders (order_id BIGINT, customer_id BIGINT, total DECIMAL(12,2)) PARTITIONED BY (bucket(32, customer_id));CREATE TABLE lake.public.visits PARTITIONED BY (bucket(64, customer_id)) AS SELECT * FROM staging.visits;ALTER TABLE lake.public.customers SET PARTITIONED BY (bucket(32, customer_id));ALTER TABLE lake.public.customers RESET PARTITIONED BY; -- unpartitioned againALTER TABLE ... SET PARTITIONED BYchanges how files are written from then on: files written before keep every bucket, so workers exchange the table’s rows until they are written again (a table created with the partitioning, or filled after it is set, is bucketed throughout).- Tables meet bucket by bucket where one count divides the other (16 and 64, 32 and 32), and their columns hash alike: integers of any width, or the same type. Choose counts of a few times the workers’ cores at least: a statement over the table runs in as many tasks.
- A write into the table writes a file a bucket, with every bucket’s file open at once and a row group of each in memory, for up to 1,024 buckets; more than that make small files. Writes of many buckets take more memory and CPU than writes of an unpartitioned table.
- Table maintenance compacts each bucket’s small files into larger files of that bucket. A table partitioned so is compacted, not clustered by its sort order.
- In Snowflake’s dialect,
CLUSTER BY (BUCKET(32, customer_id))does the same (see Snowflake SQL).
Writing rows in order
Section titled “Writing rows in order”CREATE TABLE ... AS ... ORDER BY and INSERT INTO ... SELECT ... ORDER BY into a table of the catalog write the rows in that order, so a filter
on the order’s first column reads few files, as with a clustering key.
DuckDB sorts a query’s whole result at once and spills what does
not fit in memory to the spill directory, uncompressed. A write that its
plan estimates would spill more than IGLOO_SORT_SPILL_BUDGET (half the
spill disk’s free space by default) is sorted a range of the order at a
time instead:
- A sample of the rows gives ranges of the order with about as many rows each.
- One run of the query writes its rows, compressed, into the spill directory, apart by range.
- Ranges next to each other are sorted and written together, as many as the budget allows, one batch after another in the order.
The table gets the same rows in the same order, in files that each hold
rows in order and follow one another in it. Sorting needs at most the
budget at a time, besides the compressed rows. On an m7g.2xlarge with 78 GB
of disk free, 515 million rows of a lookup table sorted by two columns took
1,344 s and at most 71 GB more disk in one sort, and 888 s and 30 GB a range
at a time. The query runs once to write
the rows (and once more for the sample), so they are what that run read.
CREATE TABLE ... AS fills the table under a temporary name, as always; an
INSERT writes its batches in one transaction, which the catalog commits
at once, with a snapshot for each batch. igloo_sorted_writes_total
counts these writes.
- Only an
ORDER BYof the result’s columns is sorted in ranges: by name, alias or position (ORDER BY audience_id, ver,ORDER BY 2 DESC NULLS FIRST), in any direction. One of other expressions (ORDER BY lower(name)) sorts at once, as before, as does one withLIMITorDISTINCT, anINSERTwith parameters or into a member table of an ID domain, and a result withHUGEINT,BIT,BIGNUMorUNIONcolumns, which Parquet files do not keep as they are. IGLOO_SORT_SPILL_BUDGET=offsorts every write at once.
Aggregates too large for memory
Section titled “Aggregates too large for memory”DuckDB keeps a group’s values in memory, for each list or string
aggregate (list, string_agg, Snowflake’s ARRAY_AGG, ARRAY_UNIQUE_AGG
and LISTAGG) and each DISTINCT aggregate, until the aggregate is done,
and does not spill them well. A CREATE TABLE ... AS that reads such an
aggregate, of more groups than a quarter of DuckDB’s memory holds their
states for as its plan estimates, fills the table in passes instead, each
over the groups whose keys hash to its number. A dbt model that grouped tens
of millions of rows into millions of groups, with several such aggregates,
ran out of memory in one run after spilling 307 GiB.
The passes give the rows one run would, since each group falls in one
pass, so Igloo runs in passes only a statement each of whose rows comes from
one group: it reads the aggregate once, through layers that only add
columns and filter rows, groups by one set of keys, and calls no function
whose value can change from one run to the next (random(), now();
error() can be called). A statement that ran out of memory in one run, or
that the replica’s memory watch stopped as the process neared its memory
limit, is filled again in passes, if it is such a statement, under what is
left of its statement timeout, and a pass that runs out of memory or is
stopped, its groups more than the plan estimated, runs again split in two,
as do the passes after it, up to 64 passes. Each pass reads the
aggregate’s input again; igloo_aggregate_passes_total counts these
tables.
Distinct counts
Section titled “Distinct counts”ANALYZE table counts the distinct values of a table’s columns and keeps
the counts in the table, for DuckDB’s planner. DuckDB estimates the rows
that a filter such as audience_id = 'a1' leaves of a table from the
column’s distinct count, and from those estimates which side of a join it
builds its hash table on. Without a count it takes a fifth of the table for
any such filter: one audience of a few thousand rows in a lookup table of
billions came out at hundreds of millions, and its join with tens of
millions of rows of facts hashed the facts rather than the audience.
ANALYZE lake.public.audience_members; -- every columnANALYZE lake.public.audience_members (audience_id); -- one, keeping the others' counts- The counts are approximate (
approx_count_distinct) and as of theANALYZE; run it again when loads change a column’s values much. A stale count changes plans, never results. - Igloo keeps the counts in the table property
igloo.distinct-counts(a JSON object of columns’ counts). Each replica takes them from the catalog when it next loads the table, and hands them to DuckDB before it plans a statement. - Columns of lists, structs, maps and unions have no count.
ANALYZEneeds the admin role, runs outside transaction blocks, and only on tables of the Iceberg catalog (not views or temporary tables).ANALYZEwithout a table is DuckDB’s own, which counts nothing in the catalog.
Column types
Section titled “Column types”Tables take DuckDB’s types that Iceberg has: numbers, text, dates and
times, BLOB, UUID, and lists (VARCHAR[]), maps (MAP(VARCHAR, BIGINT)) and structs (STRUCT(city VARCHAR, zip VARCHAR)) of them, nested
as deep as you like, which Iceberg holds as its own list, map and
struct, so that Spark, Trino and PyIceberg read them as such.
Iceberg tables of format versions 1 and 2, the ones Igloo’s catalog allows,
have no type for JSON, and Iceberg’s variant needs version 3, which
erasure requests cannot rewrite yet. A JSON or VARIANT
column is therefore a VARCHAR column holding each value’s JSON text, in
CREATE TABLE, ALTER TABLE ... ADD COLUMN and CREATE TABLE ... AS
alike; JSON inside a list, map or struct is a string holding the value’s
JSON text (JSON[] becomes VARCHAR[]). Cast to JSON to query them as
JSON; Snowflake’s dialect reads JSON text as JSON by itself, and keeps
its ARRAY and OBJECT as
lists and maps of strings.
CREATE TABLE events (id BIGINT, payload JSON, tags VARCHAR[], attrs MAP(VARCHAR, VARCHAR));INSERT INTO events VALUES (1, '{"page": "/home"}', ['new', 'mobile'], MAP {'plan': 'pro'});SELECT payload::JSON ->> '$.page', tags[1], attrs['plan'] FROM events;Transactions
Section titled “Transactions”Writes are transactional. BEGIN ... COMMIT groups statements, and as in
PostgreSQL:
- once a statement in a block fails, every statement until
COMMITorROLLBACKfails with SQLSTATE25P02, andCOMMITrolls the block back; BEGINinside a block, andCOMMITorROLLBACKoutside one, only warn;- a query string with several statements (see differences) runs them in one transaction, unless they hold transaction statements of their own.
As in Snowflake, a statement that creates, alters, renames, drops or
comments on a schema, table or view in the Iceberg catalog commits the
block first and then runs on its own; the block carries on in a new
transaction. A later ROLLBACK does not undo it, nor what came before it in
the block. Temporary tables and views stay in the block. dbt builds models
this way: CREATE TABLE ... AS, then ALTER TABLE ... RENAME TO to swap the
new table in, all in one block.
SAVEPOINT and RELEASE SAVEPOINT are accepted. ROLLBACK TO SAVEPOINT
cannot undo changes: it works when nothing changed since the savepoint,
which lets psycopg’s and SQLAlchemy’s nested blocks recover from a failed
query, and otherwise fails with SQLSTATE 0A000.
Views are stored in the Iceberg catalog as Iceberg views with DuckDB SQL, so every replica and restart sees them:
CREATE VIEW recent_orders AS SELECT * FROM orders WHERE o_orderdate > current_date - INTERVAL 30 DAY;CREATE OR REPLACE VIEW order_totals (customer, total) AS SELECT o_custkey, sum(o_totalprice) FROM lake.public.orders GROUP BY 1;ALTER VIEW order_totals RENAME TO customer_totals; -- ALTER TABLE works tooDROP VIEW IF EXISTS recent_orders;- Query a view by any name:
recent_orders,public.recent_ordersorlake.public.recent_orders. In listings (information_schema,\dv) views appear under the databasememory, where each replica keeps its copy. An unqualified name finds views on the search path as it finds tables: afterSET search_path = sales,vissales.v. Only admins may changememory, and so only they may put it first on the search path. - An unqualified name in a view is the view’s own schema’s table or view
of that name, if it has one, as in Snowflake and as the view’s Iceberg
default namespace (its schema) says: a view in
salesthat readsordersreadssales.orders, whatever the search path of the session that created it or reads it. Igloo stores such names qualified (lake.sales.orders). Other unqualified names resolve when the view is queried, against the querying session’s search path, as in DuckDB; a CTE keeps its name. Schema-qualified table names are stored with the catalog’s name:sales.ordersbecomeslake.sales.orders. - A view that a replica cannot load, because a table it reads is missing,
say, is listed with its columns but fails a statement that reads it,
directly, through other views or in a new view’s body, with the reason
(
view sales.v could not be loaded: ...). Such a statement syncs the replica’s views first, so the view loads as soon as the cause is fixed. - Creating, replacing, renaming or dropping a view takes effect at once for every session on the replica that does it. A view created on one replica reaches the others within 30 seconds, or at once when a query there names it.
- Writers create, rename and drop views, as do users with
CREATEon the view’s schema. Other engines see the views in the catalog but cannot run their DuckDB SQL.ALTER VIEWsupports onlyRENAME TO; a renamed view keeps its grants and comments, and views that read it by its old name fail until they are replaced.DROP VIEW ... CASCADEdrops only the view. - A view runs with the privileges of whoever queries it: reading one needs
SELECTon the tables it reads (see grants).
Comments
Section titled “Comments”COMMENT ON SCHEMA public IS 'Shared tables';COMMENT ON TABLE orders IS 'One row per order';COMMENT ON COLUMN orders.o_totalprice IS 'In dollars';COMMENT ON VIEW order_totals IS 'Updated live';COMMENT ON COLUMN order_totals.total IS 'Lifetime revenue';COMMENT ON TABLE orders IS NULL; -- removeComments are stored as Iceberg metadata: a comment property of the table,
view or namespace and the columns’ doc strings (a view’s in a new version of
the view), which Spark and Trino also read. Clients see them as in
PostgreSQL, through obj_description, col_description and
pg_description (psql’s \dt+ and \d+ show them), in
information_schema, in the catalog’s views such as
igloo.tables, and in one listing:
SELECT table_schema, table_name, column_name, comment FROM igloo_comments();Each user sees the comments of the objects they may see (see the catalog). Owners of an object may comment on it too. A replica rereads every table’s comments in the background every 30 seconds while queries read them, so comments set on another replica can take that long to appear.
Roles and grants
Section titled “Roles and grants”Every user has one built-in role that applies to the whole warehouse, set
with CREATE USER ... ROLE and ALTER USER ... ROLE (see
operations): admin, writer, reader,
or none, which allows nothing on its own. Grants add privileges on
schemas and tables of the Iceberg catalog, to a user directly or to a custom
role that users are given. Only admins create roles and grant; the syntax is
PostgreSQL’s:
CREATE USER nora WITH PASSWORD 'a-long-password' ROLE none;CREATE ROLE analysts;GRANT analysts TO nora;GRANT SELECT ON TABLE sales.orders TO analysts; -- TABLE is optional; views tooGRANT SELECT, INSERT ON SCHEMA staging TO analysts; -- every table in it, now and laterGRANT SELECT ON ALL TABLES IN SCHEMA finance TO analysts; -- the tables there nowGRANT CREATE ON SCHEMA sandbox TO nora;GRANT ALL PRIVILEGES ON SCHEMA sandbox TO nora; -- SELECT, INSERT, UPDATE, DELETE, CREATEGRANT SELECT ON CONNECTION crm TO analysts; -- a connection to another databaseGRANT SELECT ON SCHEMA crm.public TO nora; -- or one of its schemas, or crm.public.customersREVOKE INSERT ON SCHEMA staging FROM analysts;REVOKE analysts FROM nora;DROP ROLE [IF EXISTS] analysts;SHOW ROLES;SHOW GRANTS; -- or TO name, ON TABLE name, ON SCHEMA name, ON CONNECTION name| Privilege | On | Allows |
|---|---|---|
SELECT |
table, view or schema | Reading the table |
SELECT |
connection, or its schema or table | Reading the connection’s tables, which the built-in roles do not cover (see connections) |
INSERT |
table or schema | INSERT, COPY …, COPY INTO and MERGE … into it |
UPDATE |
table or schema | UPDATE and MERGE … |
DELETE |
table or schema | DELETE, TRUNCATE and MERGE … |
CREATE |
schema | Creating, replacing, altering, renaming, commenting on and dropping its tables and views, including CREATE TABLE AS |
ERASE |
ACCOUNT |
Erasure requests and data retentions, which otherwise need admin |
A statement runs if the user’s built-in role allows it, or if every access
it makes to the catalog is granted, to them or to one of their roles. So a
reader with INSERT on a table may insert into it, and a user with role
none may run only queries whose tables are all granted to them. How it
works and what it means:
- A grant on a schema covers every table and view in it, including ones
created later.
ALL TABLES IN SCHEMAcovers the tables and views there at the time of the grant, as in PostgreSQL. - Users with role
noneneedSELECTon everything a statement reads, including the target ofUPDATE,DELETEandMERGE, the query ofCREATE TABLE AS, and the tables behind every view (see below). They can read the system catalogs (information_schema,pg_catalog, theduckdb_*functions, the catalog’s views, which show them only what they may see) and their own history, but not files:read_parquet,read_csv,iceberg_scan,iceberg_metadata,glob,COPY ... FROMand similar functions could read any table’s files directly. Statements Igloo cannot analyze, such asPRAGMA, are refused for them with SQLSTATE42501. - Grants are checked for the table a name means as DuckDB binds it. A name
with no schema, or with a schema such as
sales.orders, is looked for along the session’s search path;sales.ordersonly in the databases whosesalesis on the path, or in the current database if none’s is, never in a connection whose schema of that name is not on the path. Where a name is found in several places on the path, users with rolenoneneed grants on each, as the statement would read the next if the first were dropped. - Views run with the querying user’s privileges: reading a view needs
SELECTon the tables it reads. Owner’s-rights views are not available. To show users only some rows or masked columns of a table, use policies. CREATEon a schema does not include reading or writing the tables made there; grant those as well.- Grants never allow what needs
admin(users, secrets,ATTACH, global settings), writing files withCOPY ... TO, temporary tables, creating or dropping schemas, or changing table properties. - Grants follow tables by name. Dropping a table or view through Igloo
removes its grants, and renaming one moves them;
CREATE OR REPLACEkeeps them. - Grant and role changes apply at once on the replica that made them and within 30 seconds on the others, also to statements prepared before.
- Table and column names are visible to every user, through the system catalogs.
A refused statement gets SQLSTATE 42501 and a message that names the
table or schema and the privilege it needs, such as permission denied for nora: SELECT on table public.orders needs the reader role or a SELECT grant.
Policies and tags
Section titled “Policies and tags”Masking policies replace a column’s values and row access policies hide rows, for every user and statement, as in Snowflake; tags classify columns and can mask every column that has them. Admins create and attach them:
CREATE MASKING POLICY mask_email AS (val VARCHAR) RETURNS VARCHAR -> CASE WHEN is_role_in_session('pii_reader') THEN val ELSE '***' END;ALTER TABLE crm.contacts ALTER COLUMN email SET MASKING POLICY mask_email;
CREATE ROW ACCESS POLICY client_rows AS (cid VARCHAR) RETURNS BOOLEAN -> is_role_in_session('admin') OR EXISTS (SELECT 1 FROM governance.client_access a WHERE a.client_id = cid AND is_role_in_session(a.role_name));ALTER TABLE crm.contacts ADD ROW ACCESS POLICY client_rows ON (client_id);
CREATE TAG pii ALLOWED_VALUES 'email', 'device_id';ALTER TAG pii SET MASKING POLICY mask_email;ALTER TABLE crm.leads ALTER COLUMN email SET TAG pii = 'email';
SHOW POLICIES;SELECT * FROM igloo.policy_references;Masking, row access policies and tags describes every statement, how policies apply and what they refuse.
ID domains
Section titled “ID domains”An ID domain gives the values of identifier columns, in every table that holds them, dense integer ids from 0: one id per person, say, across the tables of attributes, segments and events. Counting distinct people over these ids, and keeping sets of them as bitmaps, costs far less than over text identifiers. Admins create a domain with the type of its values and the tags its identifiers carry, and make columns its members:
CREATE TAG pii;CREATE ID DOMAIN people (VARCHAR) TAG pii = 'person_id' COMMENT = 'one id a person';ALTER TABLE crm.contacts ALTER COLUMN person_id SET TAG pii = 'person_id';ALTER TABLE crm.contacts ALTER COLUMN person_id SET ID DOMAIN people;SHOW ID DOMAINS;
ALTER TABLE crm.contacts ALTER COLUMN person_id UNSET ID DOMAIN;DROP ID DOMAIN people;- A domain’s values are
VARCHAR,UUID,BIGINTorINTEGER. Its dictionary, the values and their ids, is the tableigloo_domains.<domain>of the catalog, whosevaluecolumn carries the domain’s tags, so that an erasure request finds the dictionary as it finds the tables. - The dictionaries are Igloo’s own. The row access policy
igloo_id_domain_dictionary, which is false, guards each, so no user’s statement, an admin’s included, reads their rows, and they count as protected tables wherever Igloo serves tables or files (Delta Sharing, clean rooms, its Iceberg REST endpoint, reads of the warehouse’s files). No one may write to, create, drop or alter anything in the schemaigloo_domains, or change that policy; their names still show in listings. Nor may anyone put it on the search path or make it the current schema (SET search_path,SET schema,USE), whichigloo_bitmapsandigloo_refreshshare. - A member column must have the domain’s type and carry its tags.
SET ID DOMAINadds the column_igloo_id_<column>(BIGINT) beside it and records the membership in the table propertyigloo.id-domain.<column>; other Iceberg engines see that column as a nullableBIGINTthat Igloo fills and they should not write.UNSET ID DOMAINdrops it again. Like policies, memberships stay with a table’s name when it is dropped or replaced. - The columns that hold ids are Igloo’s own. Statements read member
tables as if they did not have them,
SELECT *included, views too, for every user;information_schema.columns,pg_attributeandigloo.columnsleave them out (DESCRIBEandduckdb_columns()still show their names). No statement may name a column, or anything else, beginning with_igloo_id_. Delta Sharing refuses a member table, whose files hold the ids: share a copy made withCREATE TABLE ... AS SELECT *, which leaves them out. Igloo’s Iceberg REST endpoint gives member tables to admins only, and a clean room’s dataset of one has the columns without the ids. - Igloo fills the ids. A write to a member table (
INSERT,COPY INTO,CREATE [OR REPLACE] TABLE ... ASof a member table’s name) writes the ids of the values the dictionary has as it writes the rows, and before the statement returns gives the values it lacks new ids and fills them in; withIGLOO_ID_SYNC_MIN_ROWSset, a smaller write leaves that to a pass about 30 seconds later, which the writes to a table meanwhile share. Giving new ids takes the domain’s lease for as long as one append to the dictionary takes, so writers of tables in one domain wait for each other only for that, and those of different domains never. A writer that does not get the lease within 5 seconds, writes inside a transaction block, other engines’ writes and rows whose member column anUPDATEchanged keepNULLids until maintenance fills them, at the start of its next pass. Counts through ids treat a table with such rows as not mapped, and an id is never wrong: each value has the one id its dictionary entry gives it. A fill of a million rows or more, such as a table’s first, writes the data files that hold them again, one after another, each with its rows in their order and the ids added, as compaction writes files, withinIGLOO_MAINTENANCE_MEMORY: a table laid out by a column, say by audience, keeps its layout, and filters on that column keep skipping the files and row groups they skipped. Fewer rows, and tables whose files Igloo cannot write again (with deletion vectors, or more values without ids than a quarter of that memory holds), are filled by anUPDATE. - With
IGLOO_ID_DOMAINS=true, a query’scount(DISTINCT t.c)of a member columnccounts the ids beside it instead, as 32-bit integers, which is faster and lets large counts use bitmaps; the result is the same. It does so only when the table’s current snapshot has every row’s id, and reads the table at that snapshot; a prepared statement is prepared again when the table changes. Snowflake’sCOUNT(DISTINCT c, d)counts the ids too.tmay also be a common table expression, a subquery or a view that selects the member column unchanged, by name or through a star, from another such step or from the member table, past joins, filters, windows and unnests of other columns: the ids come up the same steps in a column of their own. A view on the way is expanded in the statement, as policies expand it, for users whose role reads the whole warehouse and where no policy applies to the view. The count counts the values as written when a step on the way transforms the column, groups, combines queries (UNION), or is a common table expression that renames its columns by position, when a*or a whole-row reference to a common table expression on the way could show the ids, whentis another database’s table, when a row access policy, clean room or masking policy (onc) applies to the table for anyone, when the statement has*orCOLUMNS(...)over the table where the count reads it or uses its alias as a value, when the table reads a version or sample of its own, and in statements other than queries. A session counts the values itself withSET igloo_id_counts = off(RESET,SHOW igloo_id_counts). - Writes to a member table keep its ids right. An
INSERTthat names no columns (INSERT INTO t VALUES ...,INSERT INTO t SELECT ...) names the table’s columns other than the ids’, as does aMERGE’sINSERT VALUES; the ids of new rows start outNULL. AnUPDATE, or aMERGE’sUPDATE SET, that sets a member column sets its ids toNULLtoo, so no row keeps the id of a value it no longer holds. AMERGE‘sUPDATE BY NAME(orBY POSITION) into a member table is refused: name the columns instead. Other engines’ writes should do the same: name their columns, and set_igloo_id_<column>toNULLwhere they change<column>. UPDATE,DELETEandMERGEof member tables take the forms tables with policies take: noWITHclause before them.- Ids are never handed out twice and stay below 2^32, the range of a 32-bit
bitmap. A domain that has handed out all of them hands out no more, the
ids of values it has not seen stay
NULL, and the log says so as an error; ids never wrap.igloo_id_domain_ids_assigned_total,igloo_id_domain_rows_filled_totalandigloo_id_domain_assignments_skipped_totalcount assignments. - Columns join domains only with
IGLOO_ID_DOMAINS=true, which is off by default. Only admins change domains; anyone may list them. - A statement that counts a domain’s ids,
count(DISTINCT CAST(t._igloo_id_c AS UINTEGER)), and reads at leastIGLOO_BITMAP_MIN_ROWSrows of the catalog’s tables (10 million by default, as their metadata counts them) counts them in roaring bitmaps, a few bytes an id, where DuckDB’s hash holds every pair of group and id and spills to disk once those outgrow memory. Its results are the same. A statement whose bitmaps do not fit in the memory DuckDB has for them runs once more counting with the hash.
Bitmap indexes
Section titled “Bitmap indexes”A bitmap index keeps, for a member column of an ID domain, a
roaring bitmap of its values’ ids for each combination of the values of a
few other columns of the table: the people in each segment, say, or in each
audience’s version. Igloo builds it and keeps it up to date in the
background. Bitmap indexes exist only with IGLOO_BITMAP_INDEXES=true,
which is off by default and needs IGLOO_ID_DOMAINS=true. A session that
should count from the tables turns their reads off for itself with SET igloo_bitmap_indexes = off (RESET, SHOW igloo_bitmap_indexes).
ALTER TABLE crm.segments ADD BITMAP INDEX people_by_segment ON (segment_name) FOR person_id;ALTER TABLE crm.contacts ADD BITMAP INDEX everyone ON () FOR person_id;ALTER TABLE web.browsing ADD BITMAP INDEX by_keyword ON (ELEMENTS(keywords)) FOR person_id;SHOW BITMAP INDEXES;ALTER TABLE crm.segments DROP BITMAP INDEX people_by_segment;FORnames a member column, whose ids the bitmaps hold;ONnames up to four other columns of plain types, one bitmap for each combination of their values (ON (), one bitmap for the whole table).ON (ELEMENTS(c))keeps a bitmap for each element of the list columnc’s lists instead, of the people whose rows hold it, for the report API; counts in SQL do not read it. Only admins add and drop indexes; anyone may list them. A column keeps its domain while an index holds its ids.- An index’s bitmaps are the table
igloo_bitmaps.<name>of the catalog, in CRoaring’s portable format, one row for each combination, for one snapshot of the table, with the combination’s rows that have ids (row_count) and its distinct members (members). Tables of indexes added before Igloo recorded these leave them out; drop and add such an index for the report API to read it. Like the dictionaries, the tables are Igloo’s own: the row access policyigloo_bitmap_indexkeeps every user’s statement from their rows, no one may write to, create, drop or alter anything in the schemaigloo_bitmaps, and they count as protected wherever Igloo serves tables or files. - After a statement writes the table, and at each maintenance pass once ids
are mapped, Igloo brings the bitmaps to the table’s current snapshot: an
append adds the appended files’ bitmaps, a compaction or clustering keeps
them as they are, and anything else builds them again from the snapshot.
A snapshot whose member values do not all have ids yet gets no bitmaps
until mapping fills them in. An erasure request empties each
index of its people’s domain whose bitmaps, in any snapshot of the index’s
table, hold one of their ids, expiring the table’s other snapshots and
deleting their files, once no table’s snapshot holds the people’s values;
the index is then built again, without them, and verification counts the
index rows still holding the ids (
id_sets). A build that fails, as when object storage turns requests away under load, is tried again after 30 seconds, 2 minutes and 8 minutes, then at the next maintenance pass. Each build sizes its table’s row groups (write.parquet.row-group-size) to hold about 32 MiB of bitmaps, a bitmap of a large domain taking tens of megabytes, so that neither the build nor a statement reading them holds more than that at once a thread.SHOW BITMAP INDEXESsays which snapshot an index’s bitmaps are of, and whether that is the table’s current one. - A count of distinct members that indexes hold reads their bitmaps
instead of the table:
SELECT g, count(DISTINCT t.c) AS n FROM tbl AS t [WHERE ...] [GROUP BY g], where the keys and the filter use only the columns of an index oftblforc, and the same count of the members that are also in another table’s set,... JOIN a ON a.x = t.c, withaa table, or a CTE or subquerySELECT [DISTINCT] x FROM tbl2 [WHERE ...]filtered by the columns of an index oftbl2forx, a member of the same domain. Tables may be read through views that select their columns under the same names (a column list may name them again), from the table alone or from itLEFT JOINed to other tables of the catalog, with noWHERE, grouping,DISTINCTor limit: such a view has the table’s members (one that joins a clean room’s table is read as it is). Each select item with such a count needs a name (AS n). - Igloo reads bitmaps only when they are of the table’s current snapshot,
when no row access policy, clean room or masking policy (direct or through
a tag) applies to the table or view, the member column or the columns the
count groups and filters by, for whoever runs the statement, and when the
user’s role reads the whole warehouse (users with the role
noneread the tables). Other references to those tables in the statement read the same snapshot, and a prepared statement whose tables changed reads the tables until the bitmaps catch up. A statement whose bitmaps do not fit in the memory DuckDB has for them (rb_memory_budget) runs once more from the tables. No statement may nameigloo_bitmaps, nor reach its tables through the search path; only the reads Igloo writes skip theigloo_bitmap_indexpolicy, and any other read of an index’s table gets it, and no rows.
Erasure requests delete a person’s data from every table
whose columns are tagged with their identifiers, physically and with a
record that shows it, for GDPR and CCPA requests. Admins and holders of
ERASE ON ACCOUNT make them:
GRANT ERASE ON ACCOUNT TO privacy_officer;ERASE SUBJECT WHERE pii.email = 'ann@example.com' DRY RUN; -- what it would erase, and nothing moreERASE SUBJECT WHERE pii.email = 'ann@example.com' OR pii.device_id IN ('6F9619FF-...', '0C8C2A9E-...');SHOW ERASURE REQUESTS; -- or SELECT * FROM igloo.erasure_requestsCONFIRM ERASURE REQUEST '01a14588-...'; -- one held because it would delete much of a table; not by its requesterCANCEL ERASURE REQUEST '01a14588-...'; -- one that has not begun deletingCLOSE ERASURE REQUEST '01a14588-...'; -- admins only: the last resort for a blocked oneALTER TABLE marts.impressions SET (data_retention_days = 30);ALTER TABLE marts.impressions RESET (data_retention_days);SELECT * FROM igloo.data_retention;Query history
Section titled “Query history”Every statement and login is recorded: igloo.query_history and
igloo.login_history list them, newest first. Admins see everyone’s;
other users see their own. The catalog works out lineage and
table usage from it.
SELECT start_time, user_name, outcome, duration_ms, query_textFROM igloo.query_historyWHERE outcome <> 'ok'ORDER BY start_time DESC LIMIT 20;
SELECT event_time, user_name, result, reason, client_addressFROM igloo.login_history WHERE result = 'failure';igloo. column |
Meaning |
|---|---|
query_, session_ |
Identify the statement and the session that ran it |
user_, role |
Who ran it, and their built-in role then |
start_, end_, duration_ |
When it ran, and for how long, including sending results |
outcome, sqlstate |
ok, error, denied or canceled, and the error’s SQLSTATE |
row_ |
Rows returned or changed, or written by CREATE TABLE …, when known |
statement_ |
Such as SELECT, CREATE TABLE or GRANT |
query_ |
The statement as sent, with passwords and secrets replaced by '***' |
tables_, tables_ |
Catalog tables the statement read and wrote, as catalog., and in tables_ the connections’ tables it read, as connection.: for users with the role none, those their grants were checked for; for others, those its text names, views expanded, as worked out after it ran (see lineage); NULL when Igloo could not tell |
client_, application_ |
Where the session came from |
policies |
The masking and row access policies that applied to the statement; NULL when none did |
query_, pool |
The session’s query tag, and the compute pool of the replica that ran it |
queued_ |
Time it waited for its role limits and the replica’s |
cpu_, bytes_, memory_ |
What DuckDB measured while it ran; NULL for statements DuckDB did not run and ones that failed, 0 for those the result cache answered (see resources) |
locations_ |
Locations outside the catalog that it read files from: COPY INTO‘s, and the files a function such as read_ names; never external tables’ files, which are read through the tables |
job |
The task, pipe or materialized view it ran for, such as task nightly; NULL for a session’s own statements |
workers, stages, exchanges |
How many workers ran parts of the statement (distributed execution), in how many stages of tasks, and how many exchanges of rows from one stage to later ones the stages wrote; 0 when it ran on one replica |
plan_ |
For a statement that could run on workers, what identifies it across runs: its text without literals other than integers, and its tables’ sizes to a factor of two; auto mode runs it where it was faster before (distributed execution); NULL for others |
placement |
For such a statement, where it ran and why: this replica, how many workers, or the large worker, and auto mode’s reason, such as 4 workers: one machine should take 97 s and workers 33 s; 4 workers, (see when); NULL for others |
catalog_ |
Time it waited for the replica’s catalog lock, which DDL holds alone and preparing, binding and listings of the catalog (information_, SHOW, DESCRIBE) hold shared (see concurrency on a replica) |
igloo.login_history has event_time, user_name, result (success or
failure), reason, client_address, application_name, session_id,
auth_method (password, token, sso or access_token, when known) and
token_name, the access token a login used.
The runs of tasks, pipes, materialized views and alerts are in
igloo.task_history, the files COPY INTO loaded in
igloo.load_history, and what alerts found and sent in
igloo.alert_history, with the same rule: admins see everything, other
users their own (see loading and
alerts).
History is kept for IGLOO_AUDIT_RETENTION (90 days by default). Rows arrive
in the background, usually within a second or two of the statement ending.
Reading the views fetches history page by page, so LIMIT without ORDER BY
reads only the newest pages; filters and sorts read everything visible.
igloo.usage sums the history by day, compute pool, user, role and query
tag, with each group’s share of the day’s compute cost; see
usage and cost.
Query tags and role settings
Section titled “Query tags and role settings”SET query_tag = 'client:acme;campaign:q4'; -- recorded with every statementALTER ROLE analysts SET max_concurrent_statements = 4;ALTER ROLE analysts SET statement_timeout = '15min';ALTER ROLE analysts SET memory_limit = '8GB';ALTER USER ana SET query_tag = 'client:acme'; -- a default for her sessionsALTER ROLE analysts RESET ALL;SHOW ROLE SETTINGS;ALTER ROLE takes a custom role, a built-in role (reader means every
reader) or a user, and only admins may run it. The settings are
query_tag, statement_timeout, max_concurrent_statements,
memory_limit and sql_dialect (the SQL dialect its
sessions start in); workload management says how
they combine and how they are enforced.
Delta Sharing
Section titled “Delta Sharing”Admins share tables with outside recipients and read partners’ shares as external tables, with statements Igloo carries out itself:
CREATE SHARE acme_reporting;ALTER SHARE acme_reporting ADD TABLE marts.campaign_daily;CREATE RECIPIENT acme; -- returns a one-time activation linkGRANT SELECT ON SHARE acme_reporting TO RECIPIENT acme;
CREATE PROVIDER tvco_ads FROM '<the partner''s profile file>';CREATE EXTERNAL TABLE partners.viewership FROM SHARE tvco_ads.tv.viewing.daily;SELECT count(*) FROM partners.viewership;External tables are read-only and take grants like any table. See Delta Sharing for every statement, what recipients receive, and the security model.
Connections to other databases
Section titled “Connections to other databases”Admins connect PostgreSQL, MySQL and Snowflake databases, which Igloo then queries in place, read-only, alongside its Iceberg tables; see connections for everything about them.
CREATE CONNECTION crm TYPE postgres WITH (host 'crm.db.example.com', database 'crm', user 'igloo_ro', password 'a-long-password');-- each replica attaches it when it next startsGRANT SELECT ON SCHEMA crm.public TO analysts;SELECT count(*) FROM lake.public.audiences a JOIN crm.public.customers c ON c.email = a.email;ALTER CONNECTION crm SET (password 'a-new-password'); -- applies without a restartSHOW CONNECTIONS;DROP CONNECTION crm;A connection’s tables need a SELECT grant on them, their schema or the
connection for everyone but admins, readers and writers included, and
masking and row access policies apply to them as to Iceberg tables. The
functions that run SQL on the remote database (postgres_query,
mysql_query and the like) are refused for everyone.
Clean rooms
Section titled “Clean rooms”An agency and its partners measure overlap, reach and conversions on their joined people-level data without seeing each other’s rows, through templates every party approves:
CREATE CLEAN ROOM tv;ALTER CLEAN ROOM tv ADD COLLABORATOR agency ROLE agency_analysts;ALTER CLEAN ROOM tv ADD COLLABORATOR tvco RECIPIENT tvco_ads PROVIDER tvco;ALTER CLEAN ROOM tv ADD DATASET crm OF agency FROM marts.crm JOIN ON (email_sha256) GROUP BY (segment);ALTER CLEAN ROOM tv ADD TEMPLATE overlap FROM BUILTIN audience_overlap (left => crm.email_sha256, right => exposures.email_sha256, by => crm.segment) RUN BY (agency);ALTER CLEAN ROOM tv APPROVE TEMPLATE overlap VERSION 1;RUN CLEAN ROOM tv TEMPLATE overlap;SHOW RUNS IN CLEAN ROOM tv;Clean rooms describes every statement, what templates may do, how runs protect the data, and what they cannot protect.
Time travel
Section titled “Time travel”Every write creates an Iceberg snapshot, and you can query earlier ones:
SELECT * FROM iceberg_snapshots('lake.public.events');SELECT * FROM events AT (VERSION => 7983066988386993768);SELECT * FROM events AT (TIMESTAMP => TIMESTAMP '2026-10-01 00:00:00');Time travel reaches back as far as the snapshot retention: 7 days by default
(IGLOO_SNAPSHOT_RETENTION), or a table’s own
history.expire.max-snapshot-age-ms. Older snapshots are expired by
table maintenance. A
tag keeps a snapshot for as long as you need it.
Clones
Section titled “Clones”A clone is a full copy of a table, or of a schema’s tables and views, that costs nothing to make. It is a new Iceberg table whose metadata points at its source’s data and delete files, so no data is copied and no storage is added, however large the table: making one takes moments. From then on the two are separate tables. Writes to either go to new files of that table’s own, which the other never sees, and only those new files cost storage.
CREATE TABLE dev.orders CLONE prod.orders;CREATE OR REPLACE TABLE dev.orders CLONE prod.orders AT (TIMESTAMP => now() - INTERVAL 1 DAY);CREATE TABLE dev.orders_v7 CLONE prod.orders AT (SNAPSHOT => 7983066988386993768);CREATE TABLE dev.orders_q3 CLONE prod.orders AT (TAG => 'q3_close');CREATE SCHEMA dev CLONE prod; -- every table and viewCREATE OR REPLACE SCHEMA dev CLONE prod; -- make dev a fresh copy of prod- Which snapshot. Without
AT, the source as it is now.AT (TIMESTAMP => expression)takes the source as of a time, as far back as time travel reaches;AT (SNAPSHOT => id), orVERSION =>as in time travel, one snapshot;AT (BRANCH => 'name')orAT (TAG => 'name')the snapshot a branch or tag names. A schema is cloned as it is now or as of a time. - What it has. The source’s columns, as of the snapshot cloned, its table and column comments and its table properties, snapshot retention included. Its history starts at the snapshot cloned: time travel on the clone reaches no further back, and the source’s branches and tags are not cloned.
- Schemas.
CREATE SCHEMA ... CLONEclones every table of the source schema and copies every view’s SQL. As in Snowflake, a view’s SQL is kept as it is, so a view that readslake.prod.ordersreads the source’s table still; views that leave out the schema read whatever the reader’s search path finds. A materialized view is cloned as a table, which nothing refreshes.OR REPLACEclones each table over the one of the same name, and drops the tables and views of the schema that the source does not have. A schema clone is not atomic: if a table cannot be cloned, the error names it, the tables cloned so far stay, and running the statement again finishes the job. - Who may clone. Cloning a table needs
SELECTon it, or the reader role, andCREATEon the clone’s schema, or the writer role: whatCREATE TABLE ... AS SELECT * FROMit needs. Cloning a schema needs the writer role, as creating a schema does. - Grants. A clone starts with no grants of its own, as any new table does; grants follow names, so a clone made again under a name keeps the grants on that name. A schema’s clone gets the source schema’s own grants, which cover every table in it, now and later; grants on the source’s tables are not copied.
- Policies. A clone gets every masking policy, row access policy and tag of its source, so no user sees more of the clone than of the source: cloning is no way around policies. They are in place before the clone exists. Other replicas take up to 30 seconds to learn of a policy change, so the first clone of a table with policies under a new name waits that long before it is created; making it again under that name, as a development copy is every day, does not wait. A table of the clone’s name that has a different policy or tag value of its own is not replaced: an admin decides which applies first.
- Clean rooms. A table a clean room keeps to a party, or a schema holding one, is cloned by that party alone, and only that party reads its branches, tags and snapshots or changes them.
- Readers. Like a table made with
CREATE TABLE AS, a clone may be read by whoever may read its schema. Unlike one, it holds every row of the source behind the source’s policies, so a user whose roles a row access policy admits sees those rows in the clone, even withoutSELECTon the source. Clone tables with policies into schemas that only their intended readers can read. - History.
CLONEstatements are recorded inigloo.query_historywith the source intables_readand the clone intables_written. - Storage. Table maintenance never deletes a file a clone still reads,
whichever table is compacted, expires snapshots, loses orphan files or is
dropped; a source’s old files are deleted once no clone reads them either.
A clone made again under a name, with
OR REPLACE, deletes the files of the one it replaces, unless clones read them, and none of its source’s. See files that clones share. - Other engines. Through the Iceberg REST catalog, engines get no storage credentials for a clone, and cannot purge a table whose files clones read nor delete its files with the credentials they get for it.
- When the catalog fails. A clone the catalog made though its answer was lost, or reading the clone back failed, is kept and reported made. When Igloo cannot learn whether the catalog made it, the statement fails and says so; a clone it made is complete, and its source’s files are kept for it.
- Tables of format version 1 and encrypted tables cannot be cloned, nor can
a view on its own.
CLONEruns outside transactions.
Branches and tags
Section titled “Branches and tags”Iceberg tables can have named references to their snapshots. A tag names one snapshot and keeps it, however old it gets, until it is dropped: a quarter-end close, the table before a backfill. A branch is a line of snapshots of its own. (These are snapshot tags, not the tags that classify columns.)
ALTER TABLE events CREATE TAG q3_close; -- the current snapshotALTER TABLE events CREATE TAG before_fix AT (TIMESTAMP => TIMESTAMP '2026-10-01 00:00:00');ALTER TABLE events CREATE BRANCH audit AT (TAG => 'q3_close');ALTER TABLE events CREATE OR REPLACE BRANCH audit; -- move it to the current snapshotSELECT count(*) FROM events AT (TAG => 'q3_close');SELECT * FROM events e AT (BRANCH => 'audit') WHERE e.kind = 'click';SHOW BRANCHES ON events; -- branches and tags, main firstALTER TABLE events FAST FORWARD main TO audit;ALTER TABLE events DROP TAG IF EXISTS q3_close;ALTER TABLE events DROP BRANCH audit;ATtakes what time travel and clones take:TIMESTAMP,SNAPSHOT,BRANCHandTAG.CREATE ... IF NOT EXISTSleaves an existing branch or tag alone;OR REPLACEmoves it.- Branches are read-only in Igloo. DuckDB 1.5’s Iceberg writer commits
every
INSERT,UPDATE,DELETEandMERGEtomain, the table itself. Other engines can write to a branch, as in Spark’s write-audit-publish;FAST FORWARD main TO auditthen publishes what they wrote, and is refused ifmainhas commits the branch does not have. For changes made in Igloo, use a clone. - Reading a branch or tag reads the snapshot it names when the statement is
prepared, through the table’s grants and policies.
AT (BRANCH => ...)andAT (TAG => ...)follow a table’s name, or its alias, inFROMorJOIN. - Branches and tags are kept until they are dropped, however old, unless
a ref’s own
max-ref-age-msor the table’shistory.expire.max-ref-age-mssays otherwise. Table maintenance keeps the snapshot each names, with the files it reads, a clone’s included, and a branch’s history within the snapshot retention. - Making, moving and dropping them needs the writer role or
CREATEon the table’s schema;SHOW BRANCHESneedsSELECTon the table.maincannot be dropped.
A dbt development environment
Section titled “A dbt development environment”Each analytics engineer can build models against a full copy of production, made in seconds and costing no storage until their models change it, with the same masking and row access policies as production.
As an admin, once: give Ana a schema of her own and read access to production.
CREATE SCHEMA dbt_ana;GRANT SELECT ON SCHEMA analytics TO ana;GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON SCHEMA dbt_ana TO ana;CREATE TASK refresh_dbt_ana SCHEDULE '0 6 * * 1-5' TIMEZONE 'America/New_York' AS CREATE OR REPLACE SCHEMA dbt_ana CLONE analytics;ALTER TASK refresh_dbt_ana RESUME;Every weekday morning dbt_ana becomes a fresh copy of analytics, and
the tables she built there that production does not have are dropped. It
keeps the grants on analytics as well, so whoever may read production
may read her copy. Ana can also refresh one table herself whenever she
wants:
CREATE OR REPLACE TABLE dbt_ana.orders CLONE analytics.orders;Point dbt’s development target at her schema, with an access token as the password:
agency: target: dev outputs: dev: type: postgres host: igloo.example.com port: 5432 user: ana password: "{{ env_var('IGLOO_TOKEN') }}" dbname: igloo schema: dbt_ana threads: 4dbt build --select orders_daily+ then rebuilds just the models she
changed, and the ones downstream of them, in dbt_ana, reading every other
model from the clone; no --defer to production is needed. dbt’s own
dbt clone command creates views with the PostgreSQL adapter; run CREATE ... CLONE instead.
Loading and exporting data
Section titled “Loading and exporting data”Allow the locations to load from or export to with IGLOO_ALLOWED_LOCATIONS,
for example s3://landing-bucket/. Igloo’s storage credentials are used to
read them. Writers can then:
CREATE TABLE orders AS SELECT * FROM read_parquet('s3://landing-bucket/orders/*.parquet');INSERT INTO orders SELECT * FROM read_csv('s3://landing-bucket/new_orders.csv');COPY orders FROM 's3://landing-bucket/more_orders.parquet' (FORMAT parquet);COPY (SELECT * FROM orders WHERE o_orderdate >= DATE '2026-01-01') TO 's3://landing-bucket/export/orders_2026.parquet' (FORMAT parquet);Every other file or URL is blocked, including the server’s local disk.
To load drops from a landing bucket, COPY INTO loads every new file under
a prefix, in CSV, TSV, Parquet or JSON, compressed or not, and remembers
what it loaded so that running it again loads only new files. Pipes run it
every minute, tasks run any statement on a schedule, and materialized views
keep a query’s result as a table; Loading and scheduling
describes them all.
COPY INTO orders FROM 's3://landing-bucket/orders/' (PATTERN '.*[.]csv[.]gz');CREATE PIPE orders_drops AS COPY INTO orders FROM 's3://landing-bucket/orders/';CREATE TASK nightly SCHEDULE '0 6 * * *' TIMEZONE 'America/New_York' AS CREATE OR REPLACE TABLE order_summary AS SELECT o_orderdate, sum(o_totalprice) FROM orders GROUP BY 1;Values go to clients as these PostgreSQL types:
| DuckDB | PostgreSQL |
|---|---|
BOOLEAN |
boolean |
TINYINT, SMALLINT, UTINYINT |
smallint |
INTEGER, USMALLINT |
integer |
BIGINT, UINTEGER |
bigint |
UBIGINT, HUGEINT, UHUGEINT, DECIMAL(p, |
numeric |
FLOAT, DOUBLE |
real, double precision |
VARCHAR, ENUM |
text |
BLOB |
bytea |
UUID |
uuid |
DATE, TIME |
date, time |
TIMESTAMP (any precision), TIMESTAMPTZ |
timestamp, timestamptz |
INTERVAL |
interval |
JSON, LIST, ARRAY, STRUCT, MAP, UNION, VARIANT |
json |
GEOMETRY |
text, as WKT such as POINT (-73. |
others (TIMETZ, BIT, …) |
text |
Nested values arrive as JSON, which every PostgreSQL client can read. Over
Arrow Flight SQL, values keep DuckDB’s own Arrow types
instead, nested ones included. Sketches (sketch_hll, sketch_theta and
the others) are BLOBs, sent as bytea.
Clients
Section titled “Clients”Tested with every release, by the test suite and scripts/e2e.sh, and
weekly by scripts/bi-e2e.sh (marked BI):
| Client | Version | Notes |
|---|---|---|
| psql (libpq) | 17 | Including \dt, \d, \d+, \dn, \l, \du, \password, \copy … |
| pgx (Go) | 5.11 | Simple protocol, and the extended protocol with named and unnamed statements |
| psycopg (Python) | 3.3 | Including server-side prepared statements, server-side cursors, transactions and copy() out |
| PostgreSQL JDBC | 42.7 | DatabaseMetaData as Tableau, Looker and DBeaver call it, result metadata of prepared and LIMIT 0 queries, fetch-size paging |
| Ibis (Python) | 10.8 | Through its PostgreSQL backend: sql(), table(), expressions, to_ |
| ADBC Flight SQL driver (Python) | 1.12 | Over Arrow Flight SQL: Arrow tables, pandas and polars, parameters, adbc_ |
| pyarrow.flight | 26.0 | Over Flight SQL: handshake, get_, do_ |
| Arrow Flight SQL JDBC | 19.0 | Over Flight SQL: getTables, getColumns, prepared statements, executeUpdate, large results |
| dbt Core with dbt-postgres | 1.12, 1.11 | Seeds, views, tables, incremental append, merge and delete+insert, snapshots, tests, persist_, docs generate, source freshness; see integrations |
| SQLAlchemy with psycopg | 2.1 | The inspector and MetaData.; pandas 3 read_ and to_ |
| polars | 2.0 | read_ and write_ through SQLAlchemy, read_ through connectorx 0.4 and ADBC 1.12 |
| Npgsql (.NET, Power BI) | 4.0, 10.0 | BI: type loading, Power BI’s navigator queries, GetSchema, GetSchemaTable, parameters |
| Metabase | 0.64 | BI: sync, native and editor-built questions |
| Apache Superset (psycopg2) | 6.1 | BI: datasets, time-series charts, SQL Lab |
Tools and integrations says how to connect dbt, BI tools
and notebooks. Schema browsers read the pg_catalog and
information_schema views, which Igloo fills in from the catalog.
Connect with any PostgreSQL connection string, for example
postgres://ana@igloo.example.com:5432/igloo?sslmode=require. The database
name is ignored; dbt needs it to be the catalog’s name (see
integrations). The password may be an
access token (CREATE TOKEN), which is how people
who sign in with single sign-on, and service accounts, connect BI tools, dbt
and scripts.
Engines that read Iceberg tables themselves, such as Spark, Trino and PyIceberg, use Igloo’s tables through its Iceberg REST catalog instead, under the same users and grants; see other engines.
Differences from PostgreSQL
Section titled “Differences from PostgreSQL”- The SQL dialect is DuckDB’s (above). PostgreSQL-only features such as
stored procedures, triggers, sequences on Iceberg tables and
LISTEN/NOTIFYare not available. Row-level security is Snowflake’s kind: row access policies, notCREATE POLICY. - Users, roles and passwords are managed with
CREATE USER,ALTER USER,DROP USERandSHOW USERS(see operations), with Igloo’s own options:TYPE SERVICE,OWNER,EMAIL,LOGINandNOLOGIN,PASSWORD NULL. Access tokens are managed withCREATE TOKEN,SHOW TOKENSandDROP TOKEN, and single sign-on’s group mappings withGRANT role TO SSO GROUP 'name'(see single sign-on).GRANTandREVOKEcover tables and schemas of the Iceberg catalog (see roles and grants); there are no column privileges,GRANT OPTION,USAGEor roles granted to roles. - A query string with several statements, as
psql -cand psycopg2 (and so dbt) send them, runs them one at a time, each checked and run as if sent alone, in one transaction unless they hold transaction statements of their own. The first that fails ends the query. A prepared statement (the extended protocol) holds one statement. Statements Igloo carries out outside transactions must be sent on their own (statements on users, connections, notification integrations, policies, tags, owners, tasks, pipes and materialized views,COPY INTO,CLONE, branches and tags); several user statements may come together. - A
PIVOTthat takes its columns from the data (noIN (...)afterON) is one statement to the client, but DuckDB runs it as two: first a query that finds the columns, kept as a temporary enum type in the session. Readers and writers may run such aPIVOTin a query (a statement that starts withSELECT,FROM,PIVOT,UNPIVOTor a parenthesis), and the query that finds the columns is checked like thePIVOTbefore it runs. In other statements (CREATE TABLE AS,INSERT,EXPLAIN, or afterWITH), DuckDB would run the whole statement while preparing it, before Igloo can check it, so only admins may; others, and users with rolenoneeverywhere, list the columns, as inPIVOT sales ON quarter IN ('q1', 'q2') USING sum(amount). query()andjson_execute_serialized_sql(), which run SQL given as a string, are refused for everyone, admins included: Igloo checks a statement’s text, and cannot check SQL that a statement builds. Write the query itself instead.query_table()is limited to admins, and needs its table name written out as text, not built at run time. The functions that run SQL on other databases (postgres_query,postgres_execute,postgres_scan,mysql_query,mysql_executeand the like) are refused for everyone too, for the same reason; see connections.- The spatial extension’s GDAL readers and writers (
ST_Read,ST_Read_Meta,FROM 'x.gpkg',FROM 'x.fgb',COPY ... (FORMAT GDAL)) are refused for everyone too: GDAL opens files that a dataset names outside the sandbox.ST_ReadSHP,ST_ReadOSMand GeoParquet work; see media analytics. - Temporary tables have DuckDB’s
rowid(Iceberg tables do not), but some filters on it, such asrowid % 3 = 0orhash(rowid) % 3 = 0, fail with SQLSTATE0A000, in views too: with the spatial extension loaded, DuckDB 1.5.6 cannot plan a filter that reads onlyrowidunless it compares it with constants.rowid < 1000,rowid BETWEEN 10 AND 20androwid IN (1, 2)work. To split a table into parts, filter on its own columns, as inhash(id) % 3 = 0. ALTER ROLE ... SETandALTER USER ... SETtake Igloo’s workload settings only, not other PostgreSQL parameters.SET query_tagand Snowflake’sALTER SESSION SET QUERY_TAGset the session’s query tag.- Session settings that PostgreSQL drivers send on connect
(
application_name,extra_float_digits,DateStyleand similar) are accepted and ignored.statement_timeoutis honored.distributed_execution(auto,onoroff) is Igloo’s own: whether the session’s statements may run in parts on workers (distributed execution).SHOWandcurrent_setting()answer the PostgreSQL settings drivers read, such astransaction_isolation(repeatable read: DuckDB transactions see a snapshot),server_versionandstandard_conforming_strings. Any otherSHOW namedescribes the tablename, as in DuckDB; with no such table, it fails as PostgreSQL’s does for a setting it does not have (SQLSTATE42704,unrecognized configuration parameter "name").SETandRESETof a parameter neither DuckDB nor Igloo has fail the same way, for every user, before any check of the user’s role. - Errors carry PostgreSQL’s SQLSTATE for what is missing:
42P01for a table, view or sequence,42883for a function (no_such_function(1)),42704for a type (1::NUMBER),3F000for a schema in which a table is created,42703for a column. current_user,session_userandcurrent_role(also written with parentheses) are the signed-in user’s name. As a select list’s item of its own they name their column as in PostgreSQL (current_user), and in the Snowflake dialect as in Snowflake (CURRENT_USER()).- Transaction blocks behave as in PostgreSQL, except that changes to the
catalog commit the block first, and
ROLLBACK TO SAVEPOINTcannot undo changes (see transactions). COPY (query) TO STDOUTandCOPY table TO STDOUTwork, in text, CSV and binary format, withHEADER,DELIMITERandNULL; they needSELECTon what they read, like the query.COPY table FROM STDINloads what the client sends (loading).TO_CHARformats dates and timestamps; number formats are not supported.SETof DuckDB settings that affect every session (memory, threads, secrets) is limited to admins, as are the read cache’s functions and settings (cache_httpfs_*, see operations).pg_catalogviews are compatible enough for the clients above but are not a complete copy of PostgreSQL’s. Storage-level details (sizes, indexes, tablespaces) are empty, and so are keys: Iceberg does not keep primary or foreign keys. Temporary objects are in the schemapg_temp.lake.information_schemaandlake.pg_catalogmean the same asinformation_schemaandpg_catalog.- SQL cursors support
DECLARE ... CURSOR [WITH HOLD] FOR,FETCH [FORWARD | NEXT] [n | ALL]andCLOSE; they read forward only, andMOVEand scrollable cursors are not supported. A cursor’s whole result is computed when it is declared. - Array parameters (
= ANY($1)with a list) work when the client declares the array type or the parameter is the operand ofANYorALL, in which case it is a list of text.