Re: list fieldnames in table? (from PHP) - Mailing list pgsql-general

From Steven Klassen
Subject Re: list fieldnames in table? (from PHP)
Date
Msg-id 20041026035329.GB23780@commandprompt.com
Whole thread Raw
In response to list fieldnames in table? (from PHP)  (Miles Keaton <mileskeaton@gmail.com>)
List pgsql-general
* Miles Keaton <mileskeaton@gmail.com> [2004-10-25 19:36:43 -0700]:

> Is there a simple way to list fieldnames in a table, from PHP?
>
> When on the command-line, I just do \d tablename
>
> But how to get the fieldnames from PHP commands?

If your namespace is 'public' and your table is 'users', for example:

SELECT attname
FROM pg_namespace, pg_attribute, pg_type, pg_class
WHERE pg_type.oid = atttypid
AND pg_class.oid = attrelid
AND pg_namespace.nspname = 'public'
AND relnamespace = pg_namespace.oid
AND relname = 'users'
AND attnum >= 1;

--
Steven Klassen - Lead Programmer
Command Prompt, Inc. - http://www.commandprompt.com/
PostgreSQL Replication & Support Services, (503) 667-4564

pgsql-general by date:

Previous
From: "Mayra"
Date:
Subject: Theory!!
Next
From: Michael Fuhr
Date:
Subject: Re: list fieldnames in table? (from PHP)