【问题标题】:ERROR: syntax error at or near ";" at CREATE TABLE错误:“;”处或附近的语法错误在创建表
【发布时间】:2018-09-11 09:44:28
【问题描述】:

我学习 Postgresql。我刚刚在 Ubuntu 上安装了 PG,以用户“postgres”的身份签出并运行 psql 命令行。但是当我尝试执行 SHOW、CREATE 等命令时,我得到:

错误:“;”处或附近的语法错误

postgres@comp:/etc/postgresql/10/main$ psql
psql (10.5 (Ubuntu 10.5-1.pgdg18.04+1))
Type "help" for help.

postgres=# \c
You are now connected to database "postgres" as user "postgres".
postgres=# CREATE TABLE TEST1
postgres-# ;
ERROR:  syntax error at or near ";"
LINE 2: ;
        ^
postgres=# CREATE TABLE TEST1;
ERROR:  syntax error at or near ";"
LINE 1: CREATE TABLE TEST1;
                          ^
postgres=# CREATE TABLE 'TEST1';
ERROR:  syntax error at or near "'TEST1'"
LINE 1: CREATE TABLE 'TEST1';
                     ^
postgres=# 

我试图在 Stackoverflow 上找到相同的问题,但没有结果。我做错了什么?

【问题讨论】:

  • 我可以评论你没有在做什么。您实际上并没有指定任何列名或定义、类型等。尝试输入有效的CREATE TABLE 定义,看看是否有效。
  • 有关create table 语句语法的详细说明,请参阅manual。您可能希望从包含许多具有正确语法的示例的tutorial 开始。添加确保您了解difference between identifiers and strings

标签: sql postgresql ddl


【解决方案1】:

出现此错误是因为未指定表结构。您应该执行以下操作:

CREATE TABLE TEST1 (id bigserial primary key NOT NULL);

更多信息https://www.postgresql.org/docs/current/sql-createtable.html

【讨论】:

    猜你喜欢
    • 2017-02-20
    • 1970-01-01
    • 2017-07-15
    • 2010-12-24
    • 2016-07-10
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多