mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-30 13:11:23 +02:00
465d7e1882
This is a followup to commit 43ac12c6e6
,
which added regression tests checking that I/O functions of built-in
types are not marked volatile. Complaining in CREATE TYPE should push
developers of add-on types to fix any misdeclared functions in their
types. It's just a warning not an error, to avoid creating upgrade
problems for what might be just cosmetic mis-markings.
Aside from adding the warning code, fix a number of types that were
sloppily created in the regression tests.
75 lines
2.4 KiB
Plaintext
75 lines
2.4 KiB
Plaintext
--
|
|
-- CREATE_CAST
|
|
--
|
|
-- Create some types to test with
|
|
CREATE TYPE casttesttype;
|
|
CREATE FUNCTION casttesttype_in(cstring)
|
|
RETURNS casttesttype
|
|
AS 'textin'
|
|
LANGUAGE internal STRICT IMMUTABLE;
|
|
NOTICE: return type casttesttype is only a shell
|
|
CREATE FUNCTION casttesttype_out(casttesttype)
|
|
RETURNS cstring
|
|
AS 'textout'
|
|
LANGUAGE internal STRICT IMMUTABLE;
|
|
NOTICE: argument type casttesttype is only a shell
|
|
CREATE TYPE casttesttype (
|
|
internallength = variable,
|
|
input = casttesttype_in,
|
|
output = casttesttype_out,
|
|
alignment = int4
|
|
);
|
|
-- a dummy function to test with
|
|
CREATE FUNCTION casttestfunc(casttesttype) RETURNS int4 LANGUAGE SQL AS
|
|
$$ SELECT 1; $$;
|
|
SELECT casttestfunc('foo'::text); -- fails, as there's no cast
|
|
ERROR: function casttestfunc(text) does not exist
|
|
LINE 1: SELECT casttestfunc('foo'::text);
|
|
^
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
-- Try binary coercion cast
|
|
CREATE CAST (text AS casttesttype) WITHOUT FUNCTION;
|
|
SELECT casttestfunc('foo'::text); -- doesn't work, as the cast is explicit
|
|
ERROR: function casttestfunc(text) does not exist
|
|
LINE 1: SELECT casttestfunc('foo'::text);
|
|
^
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
SELECT casttestfunc('foo'::text::casttesttype); -- should work
|
|
casttestfunc
|
|
--------------
|
|
1
|
|
(1 row)
|
|
|
|
DROP CAST (text AS casttesttype); -- cleanup
|
|
-- Try IMPLICIT binary coercion cast
|
|
CREATE CAST (text AS casttesttype) WITHOUT FUNCTION AS IMPLICIT;
|
|
SELECT casttestfunc('foo'::text); -- Should work now
|
|
casttestfunc
|
|
--------------
|
|
1
|
|
(1 row)
|
|
|
|
-- Try I/O conversion cast.
|
|
SELECT 1234::int4::casttesttype; -- No cast yet, should fail
|
|
ERROR: cannot cast type integer to casttesttype
|
|
LINE 1: SELECT 1234::int4::casttesttype;
|
|
^
|
|
CREATE CAST (int4 AS casttesttype) WITH INOUT;
|
|
SELECT 1234::int4::casttesttype; -- Should work now
|
|
casttesttype
|
|
--------------
|
|
1234
|
|
(1 row)
|
|
|
|
DROP CAST (int4 AS casttesttype);
|
|
-- Try cast with a function
|
|
CREATE FUNCTION int4_casttesttype(int4) RETURNS casttesttype LANGUAGE SQL AS
|
|
$$ SELECT ('foo'::text || $1::text)::casttesttype; $$;
|
|
CREATE CAST (int4 AS casttesttype) WITH FUNCTION int4_casttesttype(int4) AS IMPLICIT;
|
|
SELECT 1234::int4::casttesttype; -- Should work now
|
|
casttesttype
|
|
--------------
|
|
foo1234
|
|
(1 row)
|
|
|