通过psql和puTTY连接到Postgres时auto_increment出错 [英] Error with auto_increment while conneted to Postgres via psql and puTTY

查看:298
本文介绍了通过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
);

有什么想法吗?

推荐答案

auto_increment 看起来就像您要在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.

引用该页面:


数据类型 serial bigserial 不是真正的类型,而只是
a表示方便,用于设置唯一标识符列
(类似于 AUTO_INCREMENT 属性支持

The data types serial and bigserial are not true types, but merely a notational convenience for setting up unique identifier columns (similar to the AUTO_INCREMENT property supported by some other databases).

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆