plpgsql howto question - Mailing list pgsql-interfaces

From Joost Kraaijeveld
Subject plpgsql howto question
Date
Msg-id A3D1526C98B7C1409A687E0943EAC41001EB16@obelix.askesis.nl
Whole thread Raw
Responses Re: plpgsql howto question
List pgsql-interfaces
Hi all,

I want to use a plpgsql function that returns the value of a column, depending on the arguments ( the code below does
notwork, hence the question): 

CREATE OR REPLACE FUNCTION getcustomername(text, int4) RETURNS text AS
'
BEGIN
IF $2 = 1 THEN
SELECT lastname FROM person WHERE objectid = $1;
RETURN lastname;
ELSIF $2 = 2 THEN
SELECT name into name1 from company WHERE objectid = $1;
RETURN name1;
END IF;
END
'  LANGUAGE 'plpgsql' VOLATILE;

What is the correct way of doing this?

TIA

Groeten,

Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
e-mail: J.Kraaijeveld@Askesis.nl
web: www.askesis.nl


pgsql-interfaces by date:

Previous
From: "Greg Sabino Mullane"
Date:
Subject: ANNOUNCE: DBD::Pg 1.40 release candidate 1 request for testing
Next
From: Frank van Vugt
Date:
Subject: Re: plpgsql howto question