Quantcast
Channel: Active questions tagged cte - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 207

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

$
0
0

There is an old and deprecated command in PostgreSQL that predates CREATE TABLE AS SELECT (CTAS) called SELECT ... INTO .... FROM, it supports WITH clauses / Common Table Expressions (CTE). So, for instance, I can do this..

WITH w AS (  SELECT *  FROM ( VALUES (1) ) AS t(x))SELECT *INTO fooFROM w;

But, I can't do this..

WITH w AS (  SELECT *  FROM ( VALUES (1) ) AS t(x))CREATE TABLE foo ASSELECT * FROM w;

Or, I get

ERROR:  syntax error at or near "CREATE"LINE 5: CREATE TABLE foo AS

How would I do that using the standardized CTAS syntax.


Viewing all articles
Browse latest Browse all 207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>