postgresql不存在列

时间:2016-03-09 05:53:53

标签: postgresql

这是我的sql数据。 当我在postgresql中执行此查询时出现一些错误 请帮我纠正一下。我没有这个数据库的经验。

-- ----------------------------
--  Sequence structure for tuning_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "mainpage"."tuning_id_seq";
CREATE SEQUENCE "mainpage"."tuning_id_seq" INCREMENT 1 START 4000 MAXVALUE 9223372036854775807 MINVALUE 1 CACHE 1;
ALTER TABLE "mainpage"."tuning_id_seq" OWNER TO "postgres";
-- ----------------------------
--  Table structure for tuning
-- ----------------------------
DROP TABLE IF EXISTS "mainpage"."tuning";
CREATE TABLE "mainpage"."tuning" (
    "id" int4 NOT NULL DEFAULT nextval("tuning_id_seq"::regclass),
    "motor_id" int4,
    "speed" int4,
    "freetext" varchar(200) COLLATE "default",
    "date_create" varchar(30) COLLATE "default",
    "date_change" varchar(30) COLLATE "default"
)
WITH (OIDS=FALSE);
ALTER TABLE "mainpage"."tuning" OWNER TO "postgres";

-- ----------------------------
--  Records of tuning
-- ----------------------------
BEGIN;
INSERT INTO "mainpage"."tuning" VALUES ('1', '1', '0', null, null, null);
INSERT INTO "mainpage"."tuning" VALUES ('2', '2', '0', null, null, null);
INSERT INTO "mainpage"."tuning" VALUES ('3', '3', '0', null, null, null);
COMMIT;

错误

NOTICE:  table "tuning" does not exist, skipping


ERROR:  column "tuning_id_seq" does not exist
********** Error **********

ERROR: column "tuning_id_seq" does not exist
SQL state: 42703

1 个答案:

答案 0 :(得分:0)

我认为您需要架构限定您的序列名称。

e.g:

CREATE TABLE "mainpage"."tuning" (
    "id" int4 NOT NULL DEFAULT nextval("mainpage"."tuning_id_seq"::regclass),
    "motor_id" int4,
    "speed" int4,
    "freetext" varchar(200) COLLATE "default",
    "date_create" varchar(30) COLLATE "default",
    "date_change" varchar(30) COLLATE "default"
)
WITH (OIDS=FALSE);
ALTER TABLE "mainpage"."tuning" OWNER TO "postgres";

如果没有资格, Postgres 将在public(例如不合格)架构中查找序列。 (理论上,您可以在每个模式中使用相同名称的序列)。