简体   繁体   English

不存在的 PostgreSQL INSERT INTO 表

[英]PostgreSQL INSERT INTO table that does not exist

I have some temp table:我有一些临时表:

CREATE TEMP TABLE IF NOT EXISTS temp_test (
col1 INTEGER NOT NULL,
col2 CHARACTER VARYING NOT NULL,
col3 BOOLEAN);

Then I do some inserts into temp_test (that works fine).然后我在temp_test插入一些temp_test (效果很好)。

Later, without creating a new table test , I try doing the following:后来,没有创建新表test ,我尝试执行以下操作:

INSERT INTO test(col1,col2,col3) SELECT col1,col2,col3 FROM temp_tes;

And I get the following error: ERROR: relation "test" does not exist我收到以下错误: ERROR: relation "test" does not exist

I thought that if I'm using INSERT INTO , it should create the table for me.我认为如果我使用INSERT INTO ,它应该为我创建表。 does it not?不是吗?

If it matters, I'm using PostgreSQL 9.6.16.如果重要的话,我使用的是 PostgreSQL 9.6.16。

You are wrong.你错了。 INSERT inserts into an existing table; INSERT插入到现有表中; it does not create a table.它不会创建表。

If you want to create a table, use CREATE TABLE AS :如果要创建表,请使用CREATE TABLE AS

CREATE TABLE test AS
    SELECT col1, ol2, col3
    FROM temp_tes;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM