postgresql - exactly one and two many columns postgres -


i new postgres sql server. setting function takes "posid" integer , (i think) returns rows skills table. if set return type of function "skills" error: "final statement returns many columns." if set return type "skills"[] (an array of skills?) error "final statement must return 1 column."

i'm confused what's going on. thought postgres 'seeing' that jobs id primary key on jobs table , (so expects function return 1 row) same errors or without primary key--so maybe more simple.

here code in function

select * "skills" inner join "jobs" on "skills"."skillid"="jobs"."skillid" "jobid"="posid" 

here jobs table (sometimes without pk)

create table "jobs" (   "jobid" integer not null,   "skillid" integer,   "title" character varying[],   constraint "pk" primary key ("jobid") ) 

here skills table

create table "skills" (   "skillname" character varying(50),   "skillid" integer ) 

here function (with different code. won't accept code above)

create or replace function "skillsforjob"("posid" integer)   returns "skills" 'select * "skills"'   language sql volatile   cost 100; alter function "skillsforjob"(integer)   owner postgres; 

you need use returns setof <table> return multiple rows, checkout documentation

create or replace function skillsforjob(posid integer)   returns "skills" 'select "skills".* "skills" inner join "jobs" on "skills"."skillid"="jobs"."skillid" "jobid"=$1'   language sql volatile   cost 100; alter function "skillsforjob"(integer)   owner test; 

Comments