Re: Connecting pg_attribute with pg_namespace

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Igor Korot <ikorot01(at)gmail(dot)com>, Ron Johnson <ronljohnsonjr(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Connecting pg_attribute with pg_namespace
Date: 2026-10-31 21:48:12
Message-ID: 311744.1793483292@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> writes:
> On 10/31/26 3:04 PM, Igor Korot wrote:
>> I have a schema name as a string.
>> Should I cast that value to something when I write
>> "pg_class.relnamespace = 'public'"?

> select relname from pg_catalog.pg_class where relname = 'cell_per' and
> relnamespace = 'public'::regnamespace;

Given that the original requirement was

>>> SELECT attnum FROM pg_attribute WHERE attrelid = 'my_table_name';

maybe just

SELECT attnum FROM pg_attribute
WHERE attrelid = 'my_schema_name.my_table_name'::regclass;

? But doing the joins explicitly is probably more adaptable
to more-complex cases.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Igor Korot 2026-10-31 22:04:39 Re: Connecting pg_attribute with pg_namespace
Previous Message Adrian Klaver 2026-10-31 21:43:35 Re: Connecting pg_attribute with pg_namespace