本文介绍了通过psql和puTTY连接到Postgres时auto_increment出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用PuTTY时遇到此错误。不知道为什么,对我来说...

I'm getting this error in puTTY. Not sure why, looks right to me ...

psql:pierre.sql:10: ERROR:  syntax error at or near "AUTO_INCREMENT"
LINE 2:  c_id  INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
                                ^
psql:pierre.sql:18: ERROR:  syntax error at or near "AUTO_INCREMENT"
LINE 2:  r_id  INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,

--DROP TABLE customer, reservation;
CREATE TABLE customer(
    c_id        INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
    c_ref       VARCHAR(30) NOT NULL,
    f_name      VARCHAR(30) NOT NULL,
    l_name      VARCHAR(30) NOT NULL,
    address     VARCHAR(100) NOT NULL,
    email       VARCHAR(100) NOT NULL,
    phone       VARCHAR(11) NOT NULL
);
CREATE TABLE reservation(
    r_id        INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
    c_id        VARCHAR(30) NOT NULL REFERENCES customer(c_id),
    book_date   DATE NOT NULL CHECK (book_date <= now()),
    s_time      DOUBLE NOT NULL,
    e_time      DOUBLE NOT NULL,
    amount      INTEGER NOT NULL
);

有什么想法吗?

推荐答案

看起来就像您要在MySQL中使用的东西。

auto_increment looks like something you'd use with MySQL.



但是,在这里,似乎您正在使用PostgreSQL。


But, here, it seems you are using PostgreSQL.

根据部分,PostgreSQL等效于 auto_increment serial bigserial

According to the datatype serial section of the manual, postgresql's equivalent of auto_increment is serial or bigserial.

引用该页面:

这篇关于通过psql和puTTY连接到Postgres时auto_increment出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 01:20