Ok, I'm pretty good with MsftSQL, but there's enough differences with PostgreSQL to make things confusing.
I'm having a problem declaring a function (I want a stored proc). Here's my schema
Now, when I try to run the function:
I get this error, which makes no sense to me at all.
ERROR: column a.authorid does not exist
SQL state: 42703
Context: PL/pgSQL function "testfunc" line 2 at SQL statement
Any ideas? Thanks
I'm having a problem declaring a function (I want a stored proc). Here's my schema
Code:
CREATE TABLE author
(
"authorName" character varying(100) NOT NULL,
"authorID" integer NOT NULL DEFAULT nextval('"author_authorID_seq"'::regclass),
CONSTRAINT "PK_authorID" PRIMARY KEY ("authorID"),
CONSTRAINT "UK_authorID" UNIQUE ("authorID")
)
CREATE TABLE book
(
"bookID" integer NOT NULL DEFAULT nextval('"book_bookID_seq"'::regclass),
"bookName" character varying(100) NOT NULL,
"authorID" integer NOT NULL,
CONSTRAINT book_pkey PRIMARY KEY ("bookID"),
CONSTRAINT "book_authorID_fkey" FOREIGN KEY ("authorID")
REFERENCES author ("authorID") MATCH SIMPLE
ON UPDATE RESTRICT ON DELETE RESTRICT,
CONSTRAINT "U_bookID" UNIQUE ("bookID")
)
create type t_book_author as ( bookID integer, authorID integer,
bookName varchar, authorName integer );
CREATE OR REPLACE FUNCTION testFunc( bID integer )
RETURNS SETOF t_book_author AS $$
begin
select B.bookID, B.authorID, B.bookName, A.authorName
from book B
inner join author A on A.authorID = B.authorID
where B.bookID = bID;
end;
$$ LANGUAGE plpgsql;
Code:
select testFunc( 2 )
ERROR: column a.authorid does not exist
SQL state: 42703
Context: PL/pgSQL function "testfunc" line 2 at SQL statement
Any ideas? Thanks
Comment