我有Postgres的表看起來像這樣:PostgreSQL的 - 錯誤:SQL狀態:XX000
CREATE TABLE "Population"
(
"Id" bigint NOT NULL DEFAULT nextval('"population_Id_seq"'::regclass),
"Name" character varying(255) NOT NULL,
"Description" character varying(1024),
"IsVisible" boolean NOT NULL
CONSTRAINT "pk_Population" PRIMARY KEY ("Id")
)
WITH (
OIDS=FALSE
);
和選擇功能,看起來像這樣:
CREATE OR REPLACE FUNCTION "Population_SelectAll"()
RETURNS SETOF "Population" AS
$BODY$select
"Id",
"Name",
"Description",
"IsVisible"
from "Population";
$BODY$
LANGUAGE 'sql' STABLE
COST 100
調用select函數返回預期的表中的所有行。
我需要在表中添加幾列(兩者都是數據庫中其他表的外鍵)。這給了我一個新的表DEF如下:
CREATE TABLE "Population"
(
"Id" bigint NOT NULL DEFAULT nextval('"population_Id_seq"'::regclass),
"Name" character varying(255) NOT NULL,
"Description" character varying(1024),
"IsVisible" boolean NOT NULL,
"DefaultSpeciesId" bigint NOT NULL,
"DefaultEcotypeId" bigint NOT NULL,
CONSTRAINT "pk_Population" PRIMARY KEY ("Id"),
CONSTRAINT "fk_Population_DefaultEcotypeId" FOREIGN KEY ("DefaultEcotypeId")
REFERENCES "Ecotype" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT "fk_Population_DefaultSpeciesId" FOREIGN KEY ("DefaultSpeciesId")
REFERENCES "Species" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
和功能:
調用後這些變化會導致以下錯誤消息的功能:
ERROR: could not find attribute 11 in subquery targetlist
SQL state: XX000
是什麼導致這個錯誤,我該如何解決它?我試圖刪除並重新創建列和函數 - 但發生同樣的錯誤。
平臺是運行在Windows Server上的PostgreSQL 8.4。謝謝。
您是否在添加數據後填充了「Population」,「DefaultSpeciesId」和「DefaultEcotypeId」列? – Timothy 2010-03-15 14:02:05
是的,我添加了列,向現有的錶行添加了一些值,然後在它們上設置「not null」和fk約束。 – rob 2010-03-16 10:22:25