From: | SunWuKung <Balazs(dot)Klein(at)axelero(dot)hu> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: pgsql variables from records |
Date: | 2006-03-17 21:00:55 |
Message-ID: | MPG.1e8541f49141f788989691@news.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
In article <20060317112123(dot)A11005(at)kipshouse(dot)org>, karly(at)kipshouse(dot)org
says...
> 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=
Its the second case.
Yes, arrays would be good, however I would need to refer to each value
by its subscript number eg.
Select * From sometable Where id=paramarray[1]
however in my case parameters have no logical order so I would like to
refer to them by their id, like perl hashes eg.
Select * From sometable Where id=paramarray{'max_option'}
(I know there is plperl but I've never tried that and I wouldn't want to
learn it just for this.)
Maybe this can be done by creating a type and an operator for it - I
don't know I have never tried those either.
From | Date | Subject | |
---|---|---|---|
Next Message | Merlin Moncure | 2006-03-17 21:05:24 | Re: efficiency of group by 1 order by 1 |
Previous Message | William Leite Araújo | 2006-03-17 20:46:45 | Re: Strange startup error |