BUG #14521: pg_attribute.attndims = 0 for array column

Started by Nonameabout 9 years ago3 messagesbugs
Jump to latest
#1Noname
krzysztof.heim@gmail.com

The following bug has been logged on the website:

Bug reference: 14521
Logged by: Krzysztof Heim
Email address: krzysztof.heim@gmail.com
PostgreSQL version: 9.6.1
Operating system: Ubuntu 16.04
Description:

Hello,

I have base table A with column type integer array.
I also have table B derived from table A.

When I query pg_attribute for table A, attndims shows 1 (correct), when I do
same query for table B - attndims shows 0 for same column.

Is it a bug, or it's desired behavior (since it's a derived column).

I checked documentation, and it does not say anything about behavior in case
of derived - just says if attndims is > 0 you can assume it's array.

Thanks

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Noname (#1)
Re: BUG #14521: pg_attribute.attndims = 0 for array column

krzysztof.heim@gmail.com writes:

I have base table A with column type integer array.
I also have table B derived from table A.

When I query pg_attribute for table A, attndims shows 1 (correct), when I do
same query for table B - attndims shows 0 for same column.

Is it a bug, or it's desired behavior (since it's a derived column).

We don't really care. attndims is a historical leftover and should never
be relied on for any semantically significant purpose.

TBH, my inclination would be to remove the column altogether rather than
"fix" this.

regards, tom lane

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Noname (#1)
Re: BUG #14521: pg_attribute.attndims = 0 for array column

Krzysztof Heim <krzysztof.heim@gmail.com> writes:

If I may ask, what is then the best way of checking if column is array.

The standard way for C code is to use this macro from lsyscache.h:

#define type_is_array(typid) (get_element_type(typid) != InvalidOid)

or depending on what you're doing, you might want these semantics:

/* type_is_array_domain accepts both plain arrays and domains over arrays */
#define type_is_array_domain(typid) (get_base_element_type(typid) != InvalidOid)

or then again, you might just want to check if the type has nonzero
typelem --- that would be the appropriate thing if you want to see
whether the type is subscriptable.

regards, tom lane

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs