Re: Determining the names of columns in a dynamic query

From: Decibel! <decibel(at)decibel(dot)org>
To: pgsql-general List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Determining the names of columns in a dynamic query
Date: 2009-04-24 20:54:01
Message-ID: DD7E1273-8DAE-49DD-AF15-1E56B0ADF5CE@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

My MTA says your email domain doesn't exist...

On Apr 24, 2009, at 1:27 PM, Johan Nel wrote:
> Sorry for cross posting, but seems nobody read the pgsql.sql NG.
> Have not received any response there so lets see if this create
> some reaction.
>
> Is it possible in pgsql to have something to manipulate columns
> where the column names will only be resolved during execution of
> the select statement:
>
> FOR rec IN (SELECT * FROM table)
> LOOP
> -- This is what I would like to do
> FOR col IN (rec.column_names)
> LOOP
> IF col = 'blahblah' THEN
> -- Do something
> ELSEIF col = 'nextcol'
> --
> ELSE
> -- Other column
> END IF;
> END LOOP;
> END LOOP;
>
> For the above, it does not need to be exactly the same, but are
> there a group of functions available to at least return in a
> dynamic query the number of columns, name of a column given the
> ordinal number of the column, etc?

You didn't mention, but that looks like PLPGSQL, so I'll assume that
it is.

Unfortunately, the answer is no. You'd have to use something like PL/
Perl.
--
Decibel!, aka Jim C. Nasby, Database Architect decibel(at)decibel(dot)org
Give your computer some brain candy! www.distributed.net Team #1828

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-04-24 21:11:13 Re: Can't use "any" with SQL functions
Previous Message Raymond O'Donnell 2009-04-24 20:20:26 Re: deleting function