From: | pw <p(dot)willis(at)telus(dot)net> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Querying Headers |
Date: | 2008-03-01 00:10:11 |
Message-ID: | 47C89EE3.2090306@telus.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
pw wrote:
>
> Hello,
>
> I am curious if there is a postgresql function that will
> return a list of header names based on an input query text.
>
> ie:
>
>
> select return_headers("SELECT name, date, shape FROM some_table;") as
> headers;
>
> returning:
>
> headers
> -------
> name
> date
> shape
>
>
> Thanks for any help.
>
> Pw
As a supplementary comment to this:
This information can be extracted from the pg_catalog
in several steps as follows:
CREATE VIEW testview AS (SELECT name, date, shape FROM some_table);
SELECT distinct attname FROM pg_attribute, pg_class, testview WHERE
attrelid=pg_class.oid AND pg_class.relname='testview';
/*GET THE COLUMN HEADERS HERE AND RETURN THEM*/
DROP VIEW testview;
I was however hoping someone had already created a
function that was standard.
ie:
CREATE FUNCTION return_header_names(text) RETURNS SETOF string
AS '
CREATE VIEW testview AS ($1);
SELECT distinct attname FROM pg_attribute, pg_class, testview WHERE
attrelid=pg_class.oid AND pg_class.relname='testview';
'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
Thanks again,
Pw
From | Date | Subject | |
---|---|---|---|
Next Message | Thomas Kellerer | 2008-03-01 00:21:15 | Re: Confused about CASE |
Previous Message | Adam Rich | 2008-03-01 00:02:01 | Re: Confused about CASE |