plpgsql howto question

From: "Joost Kraaijeveld" <J(dot)Kraaijeveld(at)Askesis(dot)nl>
To: <pgsql-interfaces(at)postgresql(dot)org>
Subject: plpgsql howto question
Date: 2004-12-23 14:19:54
Message-ID: A3D1526C98B7C1409A687E0943EAC41001EB16@obelix.askesis.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 not work, 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(dot)Kraaijeveld(at)Askesis(dot)nl
web: www.askesis.nl

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Frank van Vugt 2004-12-23 15:27:20 Re: plpgsql howto question
Previous Message Greg Sabino Mullane 2004-12-21 23:56:40 ANNOUNCE: DBD::Pg 1.40 release candidate 1 request for testing