How To Return a Row or Result Set

From: Ketema Harris <ketema(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: How To Return a Row or Result Set
Date: 2006-02-01 16:00:56
Message-ID: 983b67500602010800g32e5bff5nab5ab8ac06150011@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I have Postgresql 8.1 and I have attempted to follow the docs to do
the following:

I created a composite type:
create type credentials as (user_id int, admin bool);
it showed up fine:
Composite type "public.credentials"
Column | Type
---------+---------
user_id | integer
admin | boolean

I then attempted to create a function that would return this type as a
resultl set:

CREATE OR REPLACE FUNCTION "public"."recruiting_login" (_username
varchar, _password varchar) RETURNS setof credentials AS
'
begin
if _password = (select password from recruiting_users where
username = _username) then
select user_id, "admin" from recruiting_users where
username = _username;
else
select 0, false from recruiting_users;
end if;
end;
'
LANGUAGE 'plpgsql'

but when i execute this function i receive this error:

ERROR: SELECT query has no destination for result data
HINT: If you want to discard the results, use PERFORM instead.
CONTEXT: PL/pgSQL function "recruiting_login" line 3 at SQL statement

How do I accomplish this correctly?

Thanks.

Browse pgsql-novice by date

  From Date Subject
Next Message Ketema Harris 2006-02-01 16:26:47 How To Return a Row or Result Set
Previous Message Clifton Zama 2006-02-01 12:03:10 copy