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

Column names as variables in plpgsql

From: "Derrick Betts" <derrick(at)blueaxis(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Column names as variables in plpgsql
Date: 2006-06-30 22:32:38
Message-ID: 0eb901c69c95$17ccdd80$0202a8c0@main (view raw or flat)
Thread:
Lists: pgsql-novice
Is it possible to assign a column name to a variable and then use that 
variable in a SELECT statement inside a function using plpgsql?

For example:

CREATE OR REPLACE FUNCTION function_name("varchar")
  RETURNS varchar AS
$BODY$
DECLARE
column_name alias for $1;
status varchar;
BEGIN
  SELECT column_name INTO status FROM contact_table WHERE id = 1;
RETURN status;
END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;

Thanks,
Derrick 



In response to

Responses

pgsql-novice by date

Next:From: Tomer LevinboimDate: 2006-06-30 23:30:24
Subject: postgres transaction isolation when rollback
Previous:From: Andrej Ricnik-BayDate: 2006-06-30 20:37:08
Subject: Re: insert more than one rows

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