Skip to content

Run CREATE TABLE AS and SELECT INTO - #443

Merged
tamnd merged 2 commits into
mainfrom
create-table-as
Oct 20, 2026
Merged

tamnd merged 2 commits into
mainfrom
create-table-as

Conversation

@tamnd

@tamnd tamnd commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Summary

CREATE TABLE AS and SELECT ... INTO now run. The statement makes a table with a column for each column of the query, and then it writes the rows of the query into the table. The regression suite uses these statements in test_setup and in many other tests.

Changes

  • rupg-analyze adds create_table_as and select_into, which follow ExecCreateTableAs and create_ctas_internal. Each column keeps the type, the typmod and the collation of the query. A list of column names can rename the columns, and a list with too many names gives 42601.
  • A collatable column with no collation gives 42P22, as CheckAttributeType does.
  • IF NOT EXISTS gives the notice 42P07 for a table that exists. WITH NO DATA makes an empty table. The tag is then CREATE TABLE AS.
  • WITH (...) sets the options of the table and of its TOAST table.
  • rupg-session fills the table with an INSERT ... SELECT of the query, and the tag is SELECT n. If the query fails, the table is gone.
  • A SELECT with INTO is now a definition, not a query, in the simple and the extended protocol.

Known differences

  • CREATE TEMP TABLE AS, CREATE UNLOGGED TABLE AS, CREATE MATERIALIZED VIEW and CREATE TABLE AS EXECUTE give "not supported yet".
  • The analyzer does not keep an explicit COLLATE of an expression. A column such as 'x' COLLATE "C" gets the collation of its type, and two explicit collations that do not agree give no error.

Tests

connection/create_table_as.test is the output of PostgreSQL 19 for the same script in a new database. fmt, clippy, the workspace tests and the checks of xtask pass on server1.

@tamnd tamnd added kind/feature It does not do something that it must do. area/session Sessions, settings, pooling and the server runtime. area/sql The grammar, the lexer, the analyzer and the rewriter. labels Oct 20, 2026
@tamnd
tamnd merged commit 32792c9 into main Oct 20, 2026
5 checks passed
@tamnd
tamnd deleted the create-table-as branch October 20, 2026 06:38
@tamnd tamnd mentioned this pull request Oct 20, 2026
1 of 17 tasks
tamnd added a commit that referenced this pull request Oct 20, 2026
)

* Add the changelog entry for #443

* Free the rows of each run of a LATERAL relation that no tuple uses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/session Sessions, settings, pooling and the server runtime. area/sql The grammar, the lexer, the analyzer and the rewriter. kind/feature It does not do something that it must do.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant