Re: looking up field names

From: Robert Treat <rtreat(at)webmd(dot)net>
To: terry(at)greatgulfhomes(dot)com
Cc: "Postgres (E-mail)" <pgsql-general(at)postgresql(dot)org>
Subject: Re: looking up field names
Date: 2002-07-12 22:47:02
Message-ID: 1026514022.5293.22.camel@camel
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

try

SELECT count(1)
FROM pg_class c, pg_attribute a
WHERE c.relname = '<table to check>'
AND a.attrelid = c.oid
AND a.attname = '<column to check>'

hth

Robert Treat

On Fri, 2002-07-12 at 16:42, terry(at)greatgulfhomes(dot)com wrote:
> I am building a custom field engine. But I want to stop the user from
> creating custom fields of the same name as a standard field in the table.
>
> Would this suffice to find if a column already existed in a table:
>
> SELECT count(*)
> FROM pg_attribute, pg_class
> WHERE pg_class.relname = '<table to check>'
> AND pg_class.reltype = pg_attribute.attrelid
> AND pg_attribute.attname = '<column name to check>'
>
> Thanks in advance
>
> Terry Fielder
> Network Engineer
> Great Gulf Homes / Ashton Woods Homes
> terry(at)greatgulfhomes(dot)com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Marc Spitzer 2002-07-13 02:00:10 Re: XML to Postgres conversion
Previous Message suga 2002-07-12 21:51:40 Re: I am being interviewed by OReilly