pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Connecting pg_attribute with pg_namespace
6+ messages / 4 participants
[nested] [flat]

* Connecting pg_attribute with pg_namespace
@ 2026-10-31 06:08  Igor Korot <ikorot01@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Igor Korot @ 2026-10-31 06:08 UTC (permalink / raw)
  To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Hi,
How do I add schema name to

[code]
SELECT attnum FROM pg_attribute WHERE attrelid = 'my_table_name';
[/code]

Thank you.






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Connecting pg_attribute with pg_namespace
@ 2026-10-31 06:24  Ron Johnson <ronljohnsonjr@gmail.com>
  parent: Igor Korot <ikorot01@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Ron Johnson @ 2026-10-31 06:24 UTC (permalink / raw)
  To: Igor Korot <ikorot01@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Join pg_attribute.attrelid to pg_class.oid and thus you have the table's
relnamespace value.

On Sat, Oct 31, 2026 at 1:34 AM Igor Korot <ikorot01@gmail.com> wrote:

> Hi,
> How do I add schema name to
>
> [code]
> SELECT attnum FROM pg_attribute WHERE attrelid = 'my_table_name';
> [/code]
>
> Thank you.
>
>
>

-- 
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Connecting pg_attribute with pg_namespace
@ 2026-10-31 21:43  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Igor Korot <ikorot01@gmail.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Adrian Klaver @ 2026-10-31 21:43 UTC (permalink / raw)
  To: Igor Korot <ikorot01@gmail.com>; Ron Johnson <ronljohnsonjr@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

On 10/31/26 3:04 PM, Igor Korot wrote:
> Hi, Ron,
> 
> On Sat, Oct 31, 2026 at 1:24 AM Ron Johnson <ronljohnsonjr@gmail.com> wrote:
>>
>> Join pg_attribute.attrelid to pg_class.oid and thus you have the table's relnamespace value.
> 
>  From the docs:
> 
> [quote]
> relnamespace oid (references pg_namespace.oid)
> 
> The OID of the namespace that contains this relation
> [/quote]
> 
> I have a schema name as a string.
> 
> Should I cast that value to something when I write
> "pg_class.relnamespace = 'public'"?

Take a look at this link below:

https://www.postgresql.org/docs/current/datatype-oid.html

It will make your like easier.

So:

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

relname
----------
  cell_per

> 
> Thank you.
> 
>>
>> On Sat, Oct 31, 2026 at 1:34 AM Igor Korot <ikorot01@gmail.com> wrote:
>>>
>>> Hi,
>>> How do I add schema name to
>>>
>>> [code]
>>> SELECT attnum FROM pg_attribute WHERE attrelid = 'my_table_name';
>>> [/code]
>>>
>>> Thank you.
>>>
>>>
>>
>>
>> --
>> Death to <Redacted>, and butter sauce.
>> Don't boil me, I'm still alive.
>> <Redacted> lobster!
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Connecting pg_attribute with pg_namespace
@ 2026-10-31 21:48  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Tom Lane @ 2026-10-31 21:48 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Igor Korot <ikorot01@gmail.com>; Ron Johnson <ronljohnsonjr@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Adrian Klaver <adrian.klaver@aklaver.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





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Connecting pg_attribute with pg_namespace
@ 2026-10-31 22:04  Igor Korot <ikorot01@gmail.com>
  parent: Ron Johnson <ronljohnsonjr@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Igor Korot @ 2026-10-31 22:04 UTC (permalink / raw)
  To: Ron Johnson <ronljohnsonjr@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Hi, Ron,

On Sat, Oct 31, 2026 at 1:24 AM Ron Johnson <ronljohnsonjr@gmail.com> wrote:
>
> Join pg_attribute.attrelid to pg_class.oid and thus you have the table's relnamespace value.

From the docs:

[quote]
relnamespace oid (references pg_namespace.oid)

The OID of the namespace that contains this relation
[/quote]

I have a schema name as a string.

Should I cast that value to something when I write
"pg_class.relnamespace = 'public'"?

Thank you.

>
> On Sat, Oct 31, 2026 at 1:34 AM Igor Korot <ikorot01@gmail.com> wrote:
>>
>> Hi,
>> How do I add schema name to
>>
>> [code]
>> SELECT attnum FROM pg_attribute WHERE attrelid = 'my_table_name';
>> [/code]
>>
>> Thank you.
>>
>>
>
>
> --
> Death to <Redacted>, and butter sauce.
> Don't boil me, I'm still alive.
> <Redacted> lobster!






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Connecting pg_attribute with pg_namespace
@ 2026-11-01 06:01  Igor Korot <ikorot01@gmail.com>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Igor Korot @ 2026-11-01 06:01 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

On Sat, Oct 31, 2026 at 4:43 PM Adrian Klaver <adrian.klaver@aklaver.com> wrote:
>
> On 10/31/26 3:04 PM, Igor Korot wrote:
> > Hi, Ron,
> >
> > On Sat, Oct 31, 2026 at 1:24 AM Ron Johnson <ronljohnsonjr@gmail.com> wrote:
> >>
> >> Join pg_attribute.attrelid to pg_class.oid and thus you have the table's relnamespace value.
> >
> >  From the docs:
> >
> > [quote]
> > relnamespace oid (references pg_namespace.oid)
> >
> > The OID of the namespace that contains this relation
> > [/quote]
> >
> > I have a schema name as a string.
> >
> > Should I cast that value to something when I write
> > "pg_class.relnamespace = 'public'"?
>
> Take a look at this link below:
>
> https://www.postgresql.org/docs/current/datatype-oid.html
>
> It will make your like easier.
>
> So:
>
> select relname from pg_catalog.pg_class where relname = 'cell_per' and
> relnamespace = 'public'::regnamespace;
>
> relname
> ----------
>   cell_per
>

Thx.

> >
> > Thank you.
> >
> >>
> >> On Sat, Oct 31, 2026 at 1:34 AM Igor Korot <ikorot01@gmail.com> wrote:
> >>>
> >>> Hi,
> >>> How do I add schema name to
> >>>
> >>> [code]
> >>> SELECT attnum FROM pg_attribute WHERE attrelid = 'my_table_name';
> >>> [/code]
> >>>
> >>> Thank you.
> >>>
> >>>
> >>
> >>
> >> --
> >> Death to <Redacted>, and butter sauce.
> >> Don't boil me, I'm still alive.
> >> <Redacted> lobster!
> >
> >
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com






^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2026-11-01 06:01 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-31 06:08 Connecting pg_attribute with pg_namespace Igor Korot <ikorot01@gmail.com>
2026-10-31 06:24 ` Ron Johnson <ronljohnsonjr@gmail.com>
2026-10-31 22:04   ` Igor Korot <ikorot01@gmail.com>
2026-10-31 21:43     ` Adrian Klaver <adrian.klaver@aklaver.com>
2026-10-31 21:48       ` Tom Lane <tgl@sss.pgh.pa.us>
2026-11-01 06:01       ` Igor Korot <ikorot01@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox