Есть ли способ создать временную таблицу в Snowflake через SQL без необходимости писать столбцы каждый раз? С, ВСТАВИТЬ В - PullRequest
0 голосов
/ 26 мая 2020
insert into temp
select  code, 
case when code = 'S' then 1
when code = 'U' then 0
when code = 'R' then 4 
end 
from "table" r

ошибка временной таблицы - как сделать временную таблицу в снежинке, не отмечая каждый столбец

Ответы [ 2 ]

1 голос
/ 26 мая 2020
Create temp table temp as
select  code, 
case when code = 'S' then 1
when code = 'U' then 0
when code = 'R' then 4 
end 
from "table" r;
0 голосов
/ 26 мая 2020

Вам нужно только указать столбцы целевой временной таблицы, соответствующие списку столбцов в операторе select.

Да, вы должны указать все имена столбцов, включая типы данных.

create table "table" ( code varchar);

insert into "table" values ('S');
insert into "table" values ('U');
insert into "table" values ('R');

select  code, 
case when code = 'S' then 1
when code = 'U' then 0
when code = 'R' then 4 
end 
from "table" r;

Create temp table temp as
select  code, 
case when code = 'S' then 1
when code = 'U' then 0
when code = 'R' then 4 
end 
from "table" r; --SQL compilation error: Missing column specification


Create temp table temp (code varchar, code_no int) as
select  code, 
case when code = 'S' then 1
when code = 'U' then 0
when code = 'R' then 4 
end as code_no
from "table" r;

select * from temp;

Ссылка на документ: https://docs.snowflake.com/en/sql-reference/sql/insert.html#optional -параметры

...