Re: CREATE TYPE delimiter? - Mailing list pgsql-general

From Tom Lane
Subject Re: CREATE TYPE delimiter?
Date
Msg-id 2736.1004815969@sss.pgh.pa.us
Whole thread Raw
In response to Re: CREATE TYPE delimiter?  ("Command Prompt, Inc." <pgsql-general@commandprompt.com>)
Responses Re: CREATE TYPE delimiter?
List pgsql-general
"Command Prompt, Inc." <pgsql-general@commandprompt.com> writes:
> lx=# CREATE TYPE zero_array (internallength = 16, input = array_in, output = array_out, ELEMENT = zero, DELIMITER =
'|');

Oh, I see the problem.  typdelim is actually the delimiter to use when
a type is contained in an array: that is, the array subroutines look to
the element type, not the array type itself, to find the delimiter to
use.  So you'd need to have attached the DELIMITER = '|' spec to the
"zero" datatype to make it effective.  (This seems reasonable to me,
since it is the element type's formatting that determines what sort
of delimiter is sensible.)

The CREATE TYPE ref page is poorly worded on this point; I'll try to
improve it.

BTW, creation of the "zero" datatype automatically creates an associated
array type (internally named "_zero"), so there's no need for you to
try to create a "zero_array" type separately.  Indeed the above spec
will not work, because array_in and array_out are only valid for
variable-length arrays, and you've tried to specify a fixed-length type.

You might reasonably ask "why is there an ELEMENT option in CREATE TYPE,
if the system makes the correct array type automatically?"  The only
case where it's useful to use ELEMENT is when you are making a
fixed-length type that happens to be internally an array of N identical
things, and you want to allow the N things to be accessed directly by
subscripting.  For example, type "name" allows its constitutent "char"s
to be accessed this way; ditto "oidvector" and its component OIDs.
A 2-D "point" type could allow its two component floats to be accessed
like point[0] and point[1].  Note that what we have here is substructure
of a scalar datatype; it has nothing to do with the ability to assemble
arrays of names or arrays of points.

Now that I look at it, the CREATE TYPE ref page is pretty confusing
on the whole topic of array types.  I'll see what I can do with it.

            regards, tom lane

pgsql-general by date:

Previous
From: "Command Prompt, Inc."
Date:
Subject: Re: CREATE TYPE delimiter?
Next
From: "Command Prompt, Inc."
Date:
Subject: Re: CREATE TYPE delimiter?