简体   繁体   English

Postgres 9.4如果不存在则创建表,例如

[英]Postgres 9.4 Create Table if not exists like

This statement is throwing syntax errors: 该语句引发语法错误:

CREATE TABLE IF NOT EXISTS "weChat_data_abc" LIKE "weChat_data_sample"

The table weChat_data_sample exists and is empty. 表weChat_data_sample存在并且为空。

I get the error: 我得到错误:

Error : ERROR:  syntax error at or near "LIKE"

Output of SELECT VERSION(): SELECT VERSION()的输出:

PostgreSQL 9.4.4 on x86_64-apple-darwin14.4.0, compiled by Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn), 64-bit x86_64-apple-darwin14.4.0上的PostgreSQL 9.4.4,由Apple LLVM版本6.1.0(clang-602.0.53)(基于LLVM 3.6.0svn)编译,64位

Aha! 啊哈! I found the answer. 我找到了答案。 Looks like I need to wrap the LIKE clause in parenthesis. 看起来我需要将LIKE子句包装在括号中。

CREATE TABLE IF NOT EXISTS "weChat_data_abc"(LIKE "weChat_data_sample") 如果不存在,则创建表“ weChat_data_abc”(例如“ weChat_data_sample”)

Documentation Here: http://www.postgresql.org/docs/9.4/static/sql-createtable.html 此处的文档: http : //www.postgresql.org/docs/9.4/static/sql-createtable.html

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

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