Getting fields in a table through a query? 
Author Message
 Getting fields in a table through a query?

How can I get the fields in a given table via an SQL query even if there are
no records in that table? I just need the names of all the fields in a
table -- is that even possible?

Thanks!

-Mitch

---------------------------(end of broadcast)---------------------------



Sat, 24 Jul 2004 08:47:05 GMT
 Getting fields in a table through a query?

Quote:

> How can I get the fields in a given table via an SQL query even if there are
> no records in that table? I just need the names of all the fields in a
> table -- is that even possible?

select * from pg_attribute, pg_class where attrelid=pg_class.oid and
relname='<table name>' and attnum>0;
should give you all the user columns on the table specified as <table
name>

(If you want to get system columns like oid, you can leave off the
attnum>0)

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Sat, 24 Jul 2004 10:07:43 GMT
 Getting fields in a table through a query?

Quote:

> How can I get the fields in a given table via an SQL query even if there are
> no records in that table? I just need the names of all the fields in a
> table -- is that even possible?

Why not just
        select * from foo where false;
and examine the column names that come back?  Lack of any data will not
stop the system from sending column headers.

                        regards, tom lane

---------------------------(end of broadcast)---------------------------



Sat, 24 Jul 2004 23:55:01 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. Saving TMemo field data to a Blob field (Interbase Table) via SQL Update Query

2. Getting a list of Tables and fields in an access database

3. Getting Table Name from Field Properties

4. Getting all tables and fields from the database

5. Getting a list of fields in a table...

6. getting field & table constraints

7. Getting the source table from a recordset field?

8. Select getting table fields or setting variables?

9. newbie - help getting values from fields in tables

10. getting field count on an Access table

11. getting field data types of a table

12. Getting a Memo field in a table into a TMemo component


 
Powered by phpBB® Forum Software