From: | "J(dot) Greg Davidson" <greg(at)ngender(dot)net> |
---|---|
To: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | array casts that worked in 8.3 no longer work |
Date: | 2009-06-25 01:51:31 |
Message-ID: | 1245894691.5757.31.camel@shevek.puuhonua.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Dear PostgreSQL Hackers,
I have a couple of user defined types, which have reference semantics.
One is more specialized, so by Liskov I can upcast both single values
and arrays of values.
-- no problem:
CREATE CAST (derived_refs AS base_refs) WITHOUT FUNCTION AS IMPLICIT;
-- ok with pg-8.3, error with pg-8.4-b2:
CREATE CAST (_derived_refs AS _base_refs) WITHOUT FUNCTION AS IMPLICIT;
-- ERROR: 42P17: array data types are not binary-compatible
-- LOCATION: CreateCast, functioncmds.c:1648
Reading the comment in functioncmds:
/*
* We know that composite, enum and array types are never binary-
* compatible with each other. They all have OIDs embedded in them.
*/
I'm guessing that what I was doing was not safe although I have been
getting away with it quite nicely for several years.
Unfortunately I do this all over the place (I have a master ref type
and lots of specializations of it). Is there an efficient (and maybe
even easy) way to legally convert such arrays?
Thanks for any suggestions you may have,
_Greg
J. Greg Davidson
P.S. If you want a more complete example to refer to, here it is:
CREATE TYPE base_refs;
CREATE OR REPLACE
FUNCTION base_ref_in(cstring) RETURNS base_refs
AS 'pg-array-problem.so' LANGUAGE 'c' STRICT;
CREATE OR REPLACE
FUNCTION base_ref_out(base_refs) RETURNS cstring
AS 'pg-array-problem.so' LANGUAGE 'c' STRICT;
CREATE TYPE base_refs (
INTERNALLENGTH = 8,
ALIGNMENT = double,
input = base_ref_in,
output = base_ref_out,
PASSEDBYVALUE
);
CREATE TYPE derived_refs;
CREATE OR REPLACE
FUNCTION derived_ref_in(cstring) RETURNS derived_refs
AS 'pg-array-problem.so' LANGUAGE 'c' STRICT;
CREATE OR REPLACE
FUNCTION derived_ref_out(derived_refs) RETURNS cstring
AS 'pg-array-problem.so' LANGUAGE 'c' STRICT;
CREATE TYPE derived_refs (
INTERNALLENGTH = 8,
ALIGNMENT = double,
input = derived_ref_in,
output = derived_ref_out,
PASSEDBYVALUE
);
-- ** Safe Upcasts
-- no problem:
CREATE CAST (derived_refs AS base_refs)
WITHOUT FUNCTION AS IMPLICIT;
-- error with pg-8.4-b2:
CREATE CAST (_derived_refs AS _base_refs)
WITHOUT FUNCTION AS IMPLICIT;
From | Date | Subject | |
---|---|---|---|
Next Message | Fujii Masao | 2009-06-25 04:50:57 | Why does pg_standby require libpq.so.5? |
Previous Message | David E. Wheeler | 2009-06-24 23:56:11 | Re: Extensions User Design |