Re: Variable column name - Mailing list pgsql-general

From Bill Moran
Subject Re: Variable column name
Date
Msg-id 20110901111909.e4de5bed.wmoran@potentialtech.com
Whole thread Raw
In response to Re: Variable column name  ("Bob Pawley" <rjpawley@shaw.ca>)
Responses Re: Variable column name
List pgsql-general
In response to "Bob Pawley" <rjpawley@shaw.ca>:
>
> From: Bill Moran
>
> In response to "Bob Pawley" <rjpawley@shaw.ca>:
> >
> > I want to add information to multiple columns (20 - 40) by employing a
> > loop. Each pass of the loop will populate one column with an array.
> >
> > I have tried and I have read that variables can not be used to control
> > column names.
> >
> > Is there a means of working around this restriction other than creating 20
> > to 40 hard coded statements??
>
> You can generate dynamic SQL statements with plpgsql.
>
> Would it be possible for you to point me to an example??

http://www.postgresql.org/docs/9.0/static/plpgsql-statements.html
Section 39.5.4

If you're not familiar with plpgsql at all, you might want to start with
this:
http://www.postgresql.org/docs/9.0/static/plpgsql-structure.html

--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Variable column name
Next
From: Robert Treat
Date:
Subject: Re: md5 of table