pg_type.typname of array types.

Started by Dmitriy Igrishinabout 15 years ago10 messages
#1Dmitriy Igrishin
dmitigr@gmail.com

Hey hackers@,

Is it guaranteed that name of array types in pg_type system
catalog will always be prefixed by underscore or this convention
can be changed in future ?

Thanks.

--
// Dmitriy.

#2Florian Pflug
fgp@phlo.org
In reply to: Dmitriy Igrishin (#1)
Re: pg_type.typname of array types.

On Dec8, 2010, at 11:35 , Dmitriy Igrishin wrote:

Is it guaranteed that name of array types in pg_type system
catalog will always be prefixed by underscore or this convention
can be changed in future ?

What's the advantage of letting your code depend on this?

Within SQL, I suggest you write <type>[] to denote <type>'s array type. In the catalog, each pg_type row contains a references the corresponding array type (by OID) in the field "typarray".

BTW, when querying pg_type, instead of adding another join to pg_type to get the array type's name, you can simply cast the "typarray" field to "regtype". That way, should the array type happen to lie in a schema not in your search_path, the name will even be correctly schema-qualified. (In fact, it's not the cast which does the translation but rather the implicit conversion from regtype to cstring that happens when the result is transferred to the client. For further information, you might want to check out the documentation of the various reg* types provided by postgres).

Hope that helps,
Florian Pflug

#3Dmitriy Igrishin
dmitigr@gmail.com
In reply to: Florian Pflug (#2)
Re: pg_type.typname of array types.

Hey Florian,

Thank you very much!

2010/12/8 Florian Pflug <fgp@phlo.org>

On Dec8, 2010, at 11:35 , Dmitriy Igrishin wrote:

Is it guaranteed that name of array types in pg_type system
catalog will always be prefixed by underscore or this convention
can be changed in future ?

What's the advantage of letting your code depend on this?

Within SQL, I suggest you write <type>[] to denote <type>'s array type. In
the catalog, each pg_type row contains a references the corresponding array
type (by OID) in the field "typarray".

BTW, when querying pg_type, instead of adding another join to pg_type to
get the array type's name, you can simply cast the "typarray" field to
"regtype". That way, should the array type happen to lie in a schema not in
your search_path, the name will even be correctly schema-qualified. (In
fact, it's not the cast which does the translation but rather the implicit
conversion from regtype to cstring that happens when the result is
transferred to the client. For further information, you might want to check
out the documentation of the various reg* types provided by postgres).

Hope that helps,
Florian Pflug

--
// Dmitriy.

#4Andrew Dunstan
andrew@dunslane.net
In reply to: Dmitriy Igrishin (#1)
Re: pg_type.typname of array types.

On 12/08/2010 05:35 AM, Dmitriy Igrishin wrote:

Hey hackers@,

Is it guaranteed that name of array types in pg_type system
catalog will always be prefixed by underscore or this convention
can be changed in future ?

It is not guaranteed today, let alone in the future, that the array type
for x will be _x for any x.

Consider:

andrew=# create type _foo as (x int); create type foo as (y
text);select typname from pg_type where oid = (select typarray from
pg_type where typname = 'foo');
CREATE TYPE
CREATE TYPE
typname
---------
___foo
(1 row)

cheers

andrew

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dmitriy Igrishin (#1)
Re: pg_type.typname of array types.

Dmitriy Igrishin <dmitigr@gmail.com> writes:

Is it guaranteed that name of array types in pg_type system
catalog will always be prefixed by underscore

No. Read the code, or the documentation.

regards, tom lane

#6Dmitriy Igrishin
dmitigr@gmail.com
In reply to: Andrew Dunstan (#4)
Re: pg_type.typname of array types.

Hey Andrew,

Finally convinced. Thanks!

2010/12/8 Andrew Dunstan <andrew@dunslane.net>

On 12/08/2010 05:35 AM, Dmitriy Igrishin wrote:

Hey hackers@,

Is it guaranteed that name of array types in pg_type system
catalog will always be prefixed by underscore or this convention
can be changed in future ?

It is not guaranteed today, let alone in the future, that the array type
for x will be _x for any x.

Consider:

andrew=# create type _foo as (x int); create type foo as (y
text);select typname from pg_type where oid = (select typarray from
pg_type where typname = 'foo');
CREATE TYPE
CREATE TYPE
typname
---------
___foo
(1 row)

cheers

andrew

--
// Dmitriy.

#7Dmitriy Igrishin
dmitigr@gmail.com
In reply to: Tom Lane (#5)
Re: pg_type.typname of array types.

Hey Tom,

Thanks you too.
I always read the documentation, but don't want (yes, don't want)
to read a lot of code to get the answer on simple question because
life is too short for it. I think that people should helps each other :-)

2010/12/8 Tom Lane <tgl@sss.pgh.pa.us>

Dmitriy Igrishin <dmitigr@gmail.com> writes:

Is it guaranteed that name of array types in pg_type system
catalog will always be prefixed by underscore

No. Read the code, or the documentation.

regards, tom lane

--
// Dmitriy.

#8Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dmitriy Igrishin (#7)
Re: pg_type.typname of array types.

Dmitriy Igrishin <dmitigr@gmail.com> writes:

I always read the documentation, but don't want (yes, don't want)
to read a lot of code to get the answer on simple question because
life is too short for it. I think that people should helps each other :-)

Fine, but that sort of question doesn't belong on pgsql-hackers.

regards, tom lane

#9Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#8)
Re: pg_type.typname of array types.

On Wed, Dec 8, 2010 at 11:09 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Dmitriy Igrishin <dmitigr@gmail.com> writes:

I always read the documentation, but don't want (yes, don't want)
to read a lot of code to get the answer on simple question because
life is too short for it. I think that people should helps each other :-)

Fine, but that sort of question doesn't belong on pgsql-hackers.

Right. Perhaps it's useful to quote the description of the list[1]http://archives.postgresql.org/pgsql-hackers/:

The PostgreSQL developers team lives here. Discussion of current
development issues, problems and bugs, and proposed new features. If
your question cannot be answered by people in the other lists, and it
is likely that only a developer will know the answer, you may re-post
your question in this list. You must try elsewhere first!

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

[1]: http://archives.postgresql.org/pgsql-hackers/

#10Dmitriy Igrishin
dmitigr@gmail.com
In reply to: Robert Haas (#9)
Re: pg_type.typname of array types.

Okay, I understand you hint, Tom and Robert. Sorry to trouble.
I've ask here because I thought that exactly "only developer
will know the answer" on my question: "is it guaranteed ... ?".

Many thanks to Florian and Andrew for detailed explanations,
advice and etc without pointing me to the sources. Respect! :-)

2010/12/8 Robert Haas <robertmhaas@gmail.com>

On Wed, Dec 8, 2010 at 11:09 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Dmitriy Igrishin <dmitigr@gmail.com> writes:

I always read the documentation, but don't want (yes, don't want)
to read a lot of code to get the answer on simple question because
life is too short for it. I think that people should helps each other

:-)

Fine, but that sort of question doesn't belong on pgsql-hackers.

Right. Perhaps it's useful to quote the description of the list[1]:

The PostgreSQL developers team lives here. Discussion of current
development issues, problems and bugs, and proposed new features. If
your question cannot be answered by people in the other lists, and it
is likely that only a developer will know the answer, you may re-post
your question in this list. You must try elsewhere first!

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

[1] http://archives.postgresql.org/pgsql-hackers/

--
// Dmitriy.