当我执行这个查询时:
CREATE TABLE public.students (
id INTEGER PRIMARY KEY NOT NULL DEFAULT NEXTVAL('students_id_seq'::regclass),
first_name CHARACTER VARYING(20) NOT NULL,
last_name CHARACTER VARYING(20) NOT NULL,
major CHARACTER VARYING(20) NOT NULL
);
CREATE UNIQUE INDEX "Students_ID_uindex" ON students USING BTREE (id);
SELECT * FROM public.students;
我收到以下错误:
[2016-03-12 22:16:54] Run postgres.public.students [PostgreSQL - postgres@localhost]
[2016-03-12 22:16:54] Connecting TO PostgreSQL - postgres@localhost...
CREATE TABLE public.students (
id INTEGER PRIMARY KEY NOT NULL DEFAULT NEXTVAL('students_id_seq'::regclass),
first_name CHARACTER VARYING(20) NOT NULL,
last_name CHARACTER VARYING(20) NOT NULL,
major CHARACTER VARYING(20) NOT NULL
)
[2016-03-12 22:16:54] [42P07] ERROR: relation "students" already EXISTS
CREATE UNIQUE INDEX "Students_ID_uindex" ON students USING BTREE (id)
[2016-03-12 22:16:54] [42P07] ERROR: relation "Students_ID_uindex" already EXISTS
SELECT * FROM public.students
[2016-03-12 22:16:54] Executed IN 14ms ms
[2016-03-12 22:16:54] Summary: 3 OF 3 statements executed, 2 failed IN 68ms (338 symbols IN file)
知道我在做什么错吗?
更新:为了澄清我的问题,当我第一次使用新表名运行代码时,我现在得到错误,但是当我再次运行它时,我得到了上述错误。如何解决这个问题?