Postgresql - 使用 LIKE 创建表语法错误 -

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4874607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-20 00:31:43  来源:igfitidea点击:

Postgresql - CREATE TABLE SYNTAX ERROR USING LIKE -

postgresql

提问by jzafrilla

I'm trying to create a temp table from a parent table:

我正在尝试从父表创建临时表:

This is the code that I execute with pgAdmin III (or by JDBC in Java):

这是我使用 pgAdmin III(或 Java 中的 JDBC)执行的代码:

CREATE TEMP TABLE table1_tmp LIKE table1 INCLUDING DEFAULTS;

And the error I received is:

我收到的错误是:

[WARNING  ] CREATE TEMP TABLE table1_tmp LIKE table1 INCLUDING DEFAULTS
        ERROR:  syntax error at or near ?LIKE?
        LíNEA 1: CREATE TEMP TABLE table1_tmp LIKE table1 INCLUDING DEFAULTS
                                              ^

Reading postgresql 8.4 documentation, create tables using this, its very easy, but I don't understand where is the syntax problem.

阅读 postgresql 8.4 文档,使用它创建表,非常简单,但我不明白语法问题在哪里。

回答by Heiko Rupp

You need to put the like in to parens like

你需要把喜欢放在括号里

CREATE TEMP TABLE table1_tmp ( LIKE table1 INCLUDING DEFAULTS ) ;

This is not obvious from the docsif you don't count parens 1:1

如果您不计算括号 1:1,这在文档中并不明显

回答by fluminis

I'm not a Postgresql user but the manualsay that there is ( ) around the like setence.

我不是 Postgresql 用户,但手册上说类似 setence 有 ( ) 。

CREATE TEMP TABLE table1_tmp (LIKE table1 INCLUDING DEFAULTS);