通过psql和puTTY连接到Postgres时auto_increment出错 [英] Error with auto_increment while conneted to Postgres via psql and puTTY
问题描述
我在使用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
andbigserial
are not true types, but merely a notational convenience for setting up unique identifier columns (similar to theAUTO_INCREMENT
property supported by some other databases).
这篇关于通过psql和puTTY连接到Postgres时auto_increment出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!