Re: PLPGSQL

From: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
To: Shaun Clements <ShaunC(at)relyant(dot)co(dot)za>
Cc: "'pgsql-general(at)postgresql(dot)org' list" <pgsql-general(at)postgresql(dot)org>
Subject: Re: PLPGSQL
Date: 2005-03-23 14:21:50
Message-ID: 03be2df921a5540fa62acca746d8466a@mail.nih.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Mar 23, 2005, at 8:51 AM, Shaun Clements wrote:

> Hi Sean
>
> Ive chosen the table structure on purpose.
> Im transforming data from one table to another. The problem is still
> there.
> I receive the column name from a query in one table, and then need to
> update the table with that column name in another.
>
> This needs to be done dynamically as part of a loop. So the column
> name needs to be called as a variable.
> Im stuck.
>

The answer is here to allow you to construct SQL statements from parts:

http://www.postgresql.org/docs/current/static/plpgsql-
statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN

You can pass your column name as an argument to a function that does
what you want and then concatenate it with whatever else you want in
your SQL. Then just EXECUTE the resulting statement.

Sean

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2005-03-23 14:28:47 Re: inherited table and rules
Previous Message Richard Huxton 2005-03-23 14:19:21 Re: FW: PLPGSQL