iterating over relation's attributes

Started by Andrew Dunstanover 18 years ago4 messages
#1Andrew Dunstan
andrew@dunslane.net

What is the approved way to iterate over a relation's attributes? I see
that lsyscache.c::get_relnatts() is marked NOT_USED and has been for
nearly seven years. Maybe it's time to remove that code ;-)

cheers

andrew

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#1)
Re: iterating over relation's attributes

Andrew Dunstan <andrew@dunslane.net> writes:

What is the approved way to iterate over a relation's attributes?

Most places scan through the relation's tuple descriptor, rather
than expending multiple catalog lookups in pg_attribute.

regards, tom lane

#3Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#2)
Re: iterating over relation's attributes

Tom Lane wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

What is the approved way to iterate over a relation's attributes?

Most places scan through the relation's tuple descriptor, rather
than expending multiple catalog lookups in pg_attribute.

Doesn't that require me to open the relation? Is that a good thing if I
wouldn't otherwise be doing that?

This is in the context of making CheckAttributeType recurse into
composite types.

cheers

andrew

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#3)
Re: iterating over relation's attributes

Andrew Dunstan <andrew@dunslane.net> writes:

Tom Lane wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

What is the approved way to iterate over a relation's attributes?

Most places scan through the relation's tuple descriptor, rather
than expending multiple catalog lookups in pg_attribute.

Doesn't that require me to open the relation? Is that a good thing if I
wouldn't otherwise be doing that?

Sure, because whatever work gets done is likely to be amortized across
multiple uses of the relcache entry anyway.

regards, tom lane