pgsql variables from records

From: karly(at)kipshouse(dot)org
To: pgsql-general(at)postgresql(dot)org
Subject: pgsql variables from records
Date: 2006-03-17 19:21:23
Message-ID: 20060317112123.A11005@kipshouse.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

SunWuKung <Balazs(dot)Klein(at)axelero(dot)hu> wrote:
>
> I have a table in which I am storing parameters that I would like to use
> as variables in a pgsql procedure.
>
> Currently I find no other way to refer to these than to assign each
> record to a variable by a separate query like this:

I'm not sure if you are talking about referenceing the individual
columns, or a set of rows.

For the first case

DECLARE
parameters tp_method1_params;

BEGIN
....

parameters := (SELECT param1, ...paramn) FROM paramtable;

SELECT method(param1, ...paramn);

END;

Or you could declare the method to accapt the record as its input
parameter.

For the second case, use an array. I just learned how to do that
on this list a couple of days ago.

DECLARE
paramarray tp_method_params[];

BEGIN
....

paramarray := ARRAY(SELECT ....);

END;

I hope this answers the question you were asking. {-;

-karl

> Declare
> max_option integer;
>
> Select Into max_option parameter_value From parameters Where methodid=
> 999 And parameter_name='max_option'
>
> and so on for each parameter.
>
> Is there a way to get all these parameters into one variable in pgsql -
> eg. Select Into paramarray(param_name, param_value) parameter_name,
> parameter_value Where methodid=999 - and refer to their values in a
> simple way like param_array.max_option ?
>
> Thanks for the help.
> Balázs

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Stewart 2006-03-17 20:05:17 Strange startup error
Previous Message Merlin Moncure 2006-03-17 18:15:53 Re: efficiency of group by 1 order by 1