[英]PostgreSQL create temp table from query
当我使用查询 select 值到临时表时,如下所示:
drop table if exists tTemp;
select tt.id, tt.name
into tTemp
from test.TestTable tt
它的工作很棒。 但是当我在 function 中使用这个结构时,我有这个错误:
[42601] 错误:“tTemp”不是已知变量q
为什么这个结构在 function 中不起作用?
使用符合标准的 CRATE TABLE AS SELECT 而不是不鼓励的 select... 以避免将查询结果存储到 PL/pgSQL 变量和创建新表之间的歧义:
drop table if exists tTemp;
create table ttemp
as
select tt.id, tt.name
from test.TestTable tt
这是 手册建议使用 CREATE TABLE AS 而不是 select 的原因之一
它可能是工作:
INSERT INTO tTemp
select tt.id, tt.name
from test.TestTable tt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.