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

From Command Prompt, Inc.
Subject Re: CREATE TYPE delimiter?
Date
Msg-id Pine.LNX.4.30.0111031053360.27050-100000@commandprompt.com
Whole thread Raw
In response to Re: CREATE TYPE delimiter?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: CREATE TYPE delimiter?
List pgsql-general
On Sat, 3 Nov 2001, Tom Lane wrote:
>"Command Prompt, Inc." <pgsql-general@commandprompt.com> writes:
>>Just wondering if anyone knows the reason for the DELIMITER keyword in
>>CREATE TYPE? The documentation states that it sets the value delimiter if
>>you are creating an array data type, but setting this value to something
>>other than a comma neither seems to affect the input nor output
>>representation--that is, a comma still appears to be required on input,
>>and displayed on output, regardless of what I set the DELIMITER to.
>?? What was your test case exactly?  A casual perusal of arrayfuncs.c
>certainly looks like array_in and array_out use the specified delimiter
>character, not a hardwired comma.

That's what it looked like to me as well (assuming that the typdelim is
what I think it is), so I was a bit perplexed. For my test, I created an
extremely bogus type called "zero" which is just an integer which is
always set to zero. Here's what I tried:

------------------------------------------------------------------------
Built bogus "zero" type:
------------------------------------------------------------------------

lx=# CREATE FUNCTION zero_out(opaque) RETURNS opaque AS '/tmp/zero.so' LANGUAGE 'C';
CREATE
lx=# CREATE FUNCTION zero_in(opaque) RETURNS zero AS '/tmp/zero.so' LANGUAGE 'C';
NOTICE:  ProcedureCreate: type 'zero' is not yet defined
lx=# CREATE TYPE zero (internallength = 16, input = zero_in, output = zero_out);
CREATE
lx=# CREATE TABLE the_nothing (nothing zero);
CREATE
lx=# INSERT INTO the_nothing VALUES ('test');
INSERT 3841880 1
lx=# SELECT * FROM the_nothing;
 nothing
---------
 0
(1 row)

------------------------------------------------------------------------
Built bogus "zero_array" array off the "zero" type, delimited by a pipe:
------------------------------------------------------------------------

lx=# CREATE TYPE zero_array (internallength = 16, input = array_in, output = array_out, ELEMENT = zero, DELIMITER =
'|');
CREATE
lx=# CREATE TABLE na (n zero_array);
CREATE
lx=# INSERT INTO na VALUES ('{0|0}');
INSERT 3841909 1
lx=# SELECT * FROM na;
   n
-------
 {"0"}
(1 row)

lx=# INSERT INTO na VALUES ('{0,0}');
INSERT 3841910 1
lx=# SELECT * FROM na;
     n
-----------
 {"0"}
 {"0","0"}
(2 rows)

------------------------------------------------------------------------

As you can see, providing a pipe as a delimiter in the INSERT statement
caused the second value to be omitted; using the comma still worked in the
second example, but then displayed the output with a comma-delimiter.

Am I doing something wrong in the array definition possibly?


Regards,
Jw.
--
jlx@commandprompt.com
by way of pgsql-general@commandprompt.com


pgsql-general by date:

Previous
From: Gunnar Lindholm
Date:
Subject: Re: how do the pro's do this? (still a newbie)
Next
From: Tom Lane
Date:
Subject: Re: CREATE TYPE delimiter?