PostgreSQL - Error: SQL state: XX000.
- by rob
I have a table in Postgres that looks like this:
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
);
And a select function that looks like this:
CREATE OR REPLACE FUNCTION "Population_SelectAll"()
RETURNS SETOF "Population" AS
$BODY$select
"Id",
"Name",
"Description",
"IsVisible"
from "Population";
$BODY$
LANGUAGE 'sql' STABLE
COST 100
Calling the select function returns all the rows in the table as expected.
I have a need to add a couple of columns to the table (both of which are foreign keys to other tables in the database). This gives me a new table def as follows:
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
);
and function:
CREATE OR REPLACE FUNCTION "Population_SelectAll"()
RETURNS SETOF "Population" AS
$BODY$select
"Id",
"Name",
"Description",
"IsVisible",
"DefaultSpeciesId",
"DefaultEcotypeId"
from "Population";
$BODY$
LANGUAGE 'sql' STABLE
COST 100
ROWS 1000;
Calling the function after these changes results in the following error message:
ERROR: could not find attribute 11 in subquery targetlist
SQL state: XX000
What is causing this error and how do I fix it? I have tried to drop and recreate the columns and function - but the same error occurs.
Platform is PostgreSQL 8.4 running on Windows Server. Thanks.