1

I am creating function using pgAdmin4 and the CODE Basically something like

BEGIN
   RETURN QUERY
    SELECT * FROM teest."students";
END

I am just wondering, how do I set the TABLE ReturnType as TABLE(applicant_id integer, ship_id integer) something like that. There's no TABLE return type there.

Thanks

2

Either by using returns table

create function get_students()
 returns table(applicant_id integer, ship_id integer)
as
$$
  select applicant_id, ship_id
  from test.students
$$
language sql;
create function get_student_names()
 returns table(student_name text)
as
$$
  select name
  from test.students
$$
language sql;

Or by using setof

create function get_students
 returns setof students
as
$$
  select *
  from test.students
$$
language sql;
  • Thanks for the reply, sorry for saying this but I am actually using pgAdmin4 to create the function, I tried to put the code you gave me under "CODE" but apparently its not working. – David Jan 14 '18 at 11:22
  • Those are simple SQL statements, just run them. I don't use pgAdmin, but there must be a way to execute SQL statements. – a_horse_with_no_name Jan 14 '18 at 11:23
  • Thanks for the reply. Yeah, but I need to do it using pgAdmin4, the team I am working with proposes that – David Jan 14 '18 at 13:10
  • 1
    I am sure pgAdmin can run those SQL statements. – a_horse_with_no_name Jan 14 '18 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.