function to provide part of function (language='sql') - Mailing list pgsql-general

From Moray McConnachie
Subject function to provide part of function (language='sql')
Date
Msg-id 022001bf0b68$fec682b0$760e01a3@oucs.ox.ac.uk
Whole thread Raw
List pgsql-general
Hi, all.
I need to write functions along these lines:

CREATE FUNCTION functiongetfieldname(char) RETURNS varchar
AS 'SELECT fieldname FROM listoffields WHERE criterion=$1;' LANGUAGE
'sql'

CREATE FUNCTION blah(char,int2) RETURNS float
AS 'SELECT functiongetfieldname($1) FROM maintable WHERE
secondcriterion=$2;'

However, the second function obviously only returns the fieldname
returned by the first function. What I want it to do is return the
contents of the field whose name is returned by the first function. Is
this possible?

Alternative ways round considered, but I'd prefer not to mess with the
database design....

Thanks,
Moray

----------------------------------------------------------------------
----------------
Moray.McConnachie@computing-services.oxford.ac.uk


pgsql-general by date:

Previous
From: Rissman
Date:
Subject: Red Hat 6.0 / Postgresql 6.4.2 Installed / How to manage? Where are docs?
Next
From: pgomez@arrakis.es
Date:
Subject: Found a weird problem: ¿bug?