BUG #1532: typecast problem between arrays of an int8 derived datatype and varchar[]

From: "Ezequiel Tolnay" <mail(at)etolnay(dot)com(dot)ar>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #1532: typecast problem between arrays of an int8 derived datatype and varchar[]
Date: 2005-03-09 02:09:22
Message-ID: 20050309020922.0A9A8F13CA@svr2.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 1532
Logged by: Ezequiel Tolnay
Email address: mail(at)etolnay(dot)com(dot)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[]

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message cathy.hemsley 2005-03-09 11:11:46 Fault when return strings over 256 characters in PLpgSQL function
Previous Message Joe Brown 2005-03-08 17:40:02 CC Date format code defaults to current centry