Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 2639

`CREATE TABLE AS Select` (CTAS) and its associated syntax creates a new table by performing the following - Run a CREATE TABLE using the table definition of every column in the SELECT - Populating the new table with the result set of the SELECT NOTE : The table created has no indexes or constraints.

27 votes
Accepted

CREATE TABLE AS vs SELECT INTO

As a side note, the syntax for a CTAS with a CTE may look a bit weird., and SELECT INTO may also be some kind of hold over QUEL's RETRIEVE INTO. …
Evan Carroll's user avatar
  • 64.7k
2 votes
Accepted

How do I eliminate a second seq scan over a table when deriving a new table?

Answer inspired from this A few methods, all test with PostgreSQL 9.5. CROSS JOIN LATERAL ... VALUES This is actually slower, but it seems good for a first attempt.. SELECT id, x FROM foo CROSS JO …
Evan Carroll's user avatar
  • 64.7k
5 votes

PostgreSQL: Why is CREATE TABLE AS faster than CREATE ... INSERT INTO?

CREATE TABLE AS has some advantages over the other form, namely in the reduction or elimination of WAL.. Certainly optiimizations can be applied to a few commands (viz. CREATE TABLE AS, CREATE INDEX, …
Evan Carroll's user avatar
  • 64.7k
44 votes
Accepted

Using a CREATE TABLE AS SELECT how do I specify a WITH condition (CTE)?

It may be awkward, but you have to move the WITH clause from the top into the query. It's a part of the statement to generate the table, and that statement comes after the CREATE TABLE, so you would u …
Evan Carroll's user avatar
  • 64.7k