BUG #1532: typecast problem between arrays of an int8 derived datatype and varchar[] - Mailing list pgsql-bugs

From Ezequiel Tolnay
Subject BUG #1532: typecast problem between arrays of an int8 derived datatype and varchar[]
Date
Msg-id 20050309020922.0A9A8F13CA@svr2.postgresql.org
Whole thread Raw
Responses Re: BUG #1532: typecast problem between arrays of an int8 derived datatype and varchar[]
List pgsql-bugs
The following bug has been logged online:

Bug reference:      1532
Logged by:          Ezequiel Tolnay
Email address:      mail@etolnay.com.ar
PostgreSQL version: 8.0.1
Operating system:   Windows 2003 Server
Description:        typecast problem between arrays of an int8 derived
datatype and varchar[]
Details:

I've created the cardnumber_t datatype, which is an int8, to provide
implicit typecasting with varchar padding the result with zeroes.
Conversions work as expected between int4, int8, cardnumber_t and varchar.
They also work fine between int4[], int8[] and cardnumber_t[], but when an
attempt is made to convert a cardnumber_t[] to a varchar[], the connection
is dropped.

The code used to create the cardnumber_t is the following:

CREATE OR REPLACE FUNCTION cardnumber_t_in(cstring) RETURNS cardnumber_t AS
'int8in'
LANGUAGE INTERNAL IMMUTABLE WITH (isstrict);

CREATE OR REPLACE FUNCTION cardnumber_t_out(cardnumber_t) RETURNS cstring AS
'int8out'
LANGUAGE INTERNAL IMMUTABLE WITH (isstrict);

CREATE TYPE cardnumber_t (
  INTERNALLENGTH = 8,
  INPUT = cardnumber_t_in,
  OUTPUT = cardnumber_t_out,
  STORAGE = plain,
  ALIGNMENT = double
);

CREATE OR REPLACE FUNCTION to_int8(cardnumber_t) RETURNS int8 AS 'int8up'
LANGUAGE INTERNAL IMMUTABLE WITH (isstrict);

CREATE CAST (cardnumber_t AS int8) WITH FUNCTION to_int8(cardnumber_t) AS
IMPLICIT;

CREATE OR REPLACE FUNCTION to_cardnumber_t(int8) RETURNS cardnumber_t AS
'int8up'
LANGUAGE INTERNAL IMMUTABLE WITH (isstrict);

CREATE CAST (int8 AS cardnumber_t) WITH FUNCTION to_cardnumber_t(int8) AS
IMPLICIT;

CREATE OR REPLACE FUNCTION to_cardnumber_t(int4) RETURNS cardnumber_t AS
'int48'
LANGUAGE INTERNAL IMMUTABLE WITH (isstrict);

CREATE CAST (int4 AS cardnumber_t) WITH FUNCTION to_cardnumber_t(int4) AS
IMPLICIT;

CREATE DOMAIN cardnumber AS cardnumber_t CONSTRAINT ch_cardnumber_range
CHECK (VALUE between 1 AND 9999999999999999);

CREATE OR REPLACE FUNCTION fc_cardnumber_t_to_varchar (cn cardnumber_t)
RETURNS varchar AS $$
BEGIN
  RETURN substring((10000000000000000::int8+cn)::varchar, 2, 16);
END; $$ LANGUAGE plpgsql;

CREATE CAST (cardnumber_t as varchar) WITH FUNCTION
fc_cardnumber_t_to_varchar(cardnumber_t) AS IMPLICIT;

The following are successful typecast tests:
SELECT 10::int4::int8::cardnumber_t::varchar
SELECT ((ARRAY[1,2,3])::int8[])::cardnumber_t[]

The following fails and drops the connection
SELECT ((ARRAY[1,2,3])::cardnumber_t[])::varchar[]

pgsql-bugs by date:

Previous
From: "Qingqing Zhou"
Date:
Subject: Re: could not read, could not write, could not fsync, Windows 2000, PostgreSQL 8.0.1
Next
From: "Avram"
Date:
Subject: BUG #1530: search on uuid indexed article returns no resultat