Thread: pg_type.typname of array types.

pg_type.typname of array types.

From
Dmitriy Igrishin
Date:
Hey hackers@,<br /><br />Is it guaranteed that name of array types in pg_type system<br />catalog will always be
prefixedby underscore or this convention<br />can be changed in future ?<br /><br />Thanks.<br clear="all" /><br />--
<br/>// Dmitriy.<br /><br /><br /> 

Re: pg_type.typname of array types.

From
Florian Pflug
Date:
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
referencesthe 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,
thename will even be correctly schema-qualified. (In fact, it's not the cast which does the translation but rather the
implicitconversion 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



Re: pg_type.typname of array types.

From
Dmitriy Igrishin
Date:
Hey Florian,<br /><br />Thank you very much!<br /><br /><div class="gmail_quote">2010/12/8 Florian Pflug <span
dir="ltr"><<ahref="mailto:fgp@phlo.org">fgp@phlo.org</a>></span><br /><blockquote class="gmail_quote"
style="margin:0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">On
Dec8,2010, at 11:35 , Dmitriy Igrishin wrote:<br /> > Is it guaranteed that name of array types in pg_type system<br
/>> catalog will always be prefixed by underscore or this convention<br /> > can be changed in future ?<br /><br
/></div>What'sthe advantage of letting your code depend on this?<br /><br /> Within SQL, I suggest you write
<type>[]to denote <type>'s array type. In the catalog, each pg_type row contains a references the
correspondingarray type (by OID) in the field "typarray".<br /><br /> BTW, when querying pg_type, instead of adding
anotherjoin to pg_type to get the array type's name, you can simply cast the "typarray" field to "regtype". That way,
shouldthe 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
tocstring that happens when the result is transferred to the client. For further information, you might want to check
outthe documentation of the various reg* types provided by postgres).<br /><br /> Hope that helps,<br /><font
color="#888888">FlorianPflug<br /><br /></font></blockquote></div><br /><br clear="all" /><br />-- <br />// Dmitriy.<br
/><br/><br /> 

Re: pg_type.typname of array types.

From
Andrew Dunstan
Date:

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
typarrayfrom   pg_type where typname = 'foo');   CREATE TYPE   CREATE TYPE     typname   ---------     ___foo   (1
row)


cheers

andrew



Re: pg_type.typname of array types.

From
Tom Lane
Date:
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


Re: pg_type.typname of array types.

From
Dmitriy Igrishin
Date:
Hey Andrew,<br /><br />Finally convinced. Thanks!<br /><br /><div class="gmail_quote">2010/12/8 Andrew Dunstan <span
dir="ltr"><<ahref="mailto:andrew@dunslane.net">andrew@dunslane.net</a>></span><br /><blockquote
class="gmail_quote"style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left:
1ex;"><divclass="im"><br /><br /> On 12/08/2010 05:35 AM, Dmitriy Igrishin wrote:<br /><blockquote class="gmail_quote"
style="margin:0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> Hey hackers@,<br /><br
/>Is it guaranteed that name of array types in pg_type system<br /> catalog will always be prefixed by underscore or
thisconvention<br /> can be changed in future ?<br /><br /><br /></blockquote><br /><br /></div> It is not guaranteed
today,let alone in the future, that the array type for x will be _x for any x.<br /><br /> Consider:<br /><br />  
andrew=#create type _foo as (x int); create type foo as (y<br />   text);select typname from pg_type where oid =
(selecttyparray from<br />   pg_type where typname = 'foo');<br />   CREATE TYPE<br />   CREATE TYPE<br />    
typname<br/>   ---------<br />     ___foo<br />   (1 row)<br /><br /><br /> cheers<br /><font color="#888888"><br />
andrew<br/><br /></font></blockquote></div><br /><br clear="all" /><br />-- <br />// Dmitriy.<br /><br /><br /> 

Re: pg_type.typname of array types.

From
Dmitriy Igrishin
Date:
Hey Tom,<br /><br />Thanks you too.<br />I always read the documentation, but don't want (yes, don't want)<br />to read
alot of code to get the answer on simple question because<br />life is too short for it. I think that people should
helpseach other :-)<br /><br /><div class="gmail_quote">2010/12/8 Tom Lane <span dir="ltr"><<a
href="mailto:tgl@sss.pgh.pa.us">tgl@sss.pgh.pa.us</a>></span><br/><blockquote class="gmail_quote" style="margin: 0pt
0pt0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">Dmitriy Igrishin <<a
href="mailto:dmitigr@gmail.com">dmitigr@gmail.com</a>>writes:<br /> > Is it guaranteed that name of array types
inpg_type system<br /> > catalog will always be prefixed by underscore<br /><br /></div>No.  Read the code, or the
documentation.<br/><br />                        regards, tom lane<br /></blockquote></div><br /><br clear="all" /><br
/>--<br />// Dmitriy.<br /><br /><br /> 

Re: pg_type.typname of array types.

From
Tom Lane
Date:
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


Re: pg_type.typname of array types.

From
Robert Haas
Date:
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/


Re: pg_type.typname of array types.

From
Dmitriy Igrishin
Date:
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.