Re: CREATE TYPE delimiter?

From: "Command Prompt, Inc(dot)" <pgsql-general(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: CREATE TYPE delimiter?
Date: 2001-11-03 19:13:07
Message-ID: Pine.LNX.4.30.0111031053360.27050-100000@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, 3 Nov 2001, Tom Lane wrote:
>"Command Prompt, Inc." <pgsql-general(at)commandprompt(dot)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(at)commandprompt(dot)com
by way of pgsql-general(at)commandprompt(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gunnar Lindholm 2001-11-03 19:14:34 Re: how do the pro's do this? (still a newbie)
Previous Message Tom Lane 2001-11-03 18:51:15 Re: CREATE TYPE delimiter?