What is the best way to select all user defined field names in a table?

Started by Yasuo Ohgakiabout 25 years ago2 messagesgeneral
Jump to latest
#1Yasuo Ohgaki
yasuo_ohgaki@hotmail.com

I'm wandering what is the best way to get all user fields from a table using
SQL.

With following SQL, I get extra field names that is not defined by user.
(cmax,
cmin, etc)

select a.attname from pg_class as c, pg_attribute as a where c.oid =
a.attrelid and c.relname = 'table_name';

It seems pg_attribute does not have flag to distinguish user defined fields.
(Is it?)
An option is excluding all system fields in where clause one by one, but I
thought there might be a better way to do that. (I searched recent mail list
archive, couldn't find one)

Thanks,

--
Yasuo Ohgaki

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Yasuo Ohgaki (#1)
Re: What is the best way to select all user defined field names in a table?

"Yasuo Ohgaki" <yasuo_ohgaki@hotmail.com> writes:

It seems pg_attribute does not have flag to distinguish user defined fields.

attnum > 0 indicates a user field.

regards, tom lane