Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Snowflake Create table with subset of columns populated from Select statement

On Snowflake is there a way to create table with subset of columns populated from Select statement from other tables ?

From the examples I see on documentation, we can either populate all the columns through Select from other tables or populate none of the columns.

like image 467
Vinod Jayachandran Avatar asked Oct 27 '25 13:10

Vinod Jayachandran


1 Answers

One way would be to select NULL cast to the desired data type, with an alias as part of the SELECT statement.

CREATE TABLE t1 AS
SELECT
    col1,
    col2,
    NULL::timestamp_ntz AS col3,
    NULL::number AS col4
FROM t2;

This example would create a table t1 with four columns, two of which come from t2.

like image 73
bradleykirwan Avatar answered Oct 30 '25 14:10

bradleykirwan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!