Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-interfaces by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group