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
witheach 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;