Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1d2e16

Browse files
committed
Add test case for CREATE CAST.
1 parent092bc49 commita1d2e16

File tree

4 files changed

+132
-3
lines changed

4 files changed

+132
-3
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
--
2+
-- CREATE_CAST
3+
--
4+
-- Create some types to test with
5+
CREATE TYPE casttesttype;
6+
CREATE FUNCTION casttesttype_in(cstring)
7+
RETURNS casttesttype
8+
AS 'textin'
9+
LANGUAGE internal STRICT;
10+
NOTICE: return type casttesttype is only a shell
11+
CREATE FUNCTION casttesttype_out(casttesttype)
12+
RETURNS cstring
13+
AS 'textout'
14+
LANGUAGE internal STRICT;
15+
NOTICE: argument type casttesttype is only a shell
16+
CREATE TYPE casttesttype (
17+
internallength = variable,
18+
input = casttesttype_in,
19+
output = casttesttype_out,
20+
alignment = int4
21+
);
22+
-- a dummy function to test with
23+
CREATE FUNCTION casttestfunc(casttesttype) RETURNS int4 LANGUAGE SQL AS
24+
$$ SELECT 1; $$;
25+
SELECT casttestfunc('foo'::text); -- fails, as there's no cast
26+
ERROR: function casttestfunc(text) does not exist
27+
LINE 1: SELECT casttestfunc('foo'::text);
28+
^
29+
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
30+
-- Try binary coercion cast
31+
CREATE CAST (text AS casttesttype) WITHOUT FUNCTION;
32+
SELECT casttestfunc('foo'::text); -- doesn't work, as the cast is explicit
33+
ERROR: function casttestfunc(text) does not exist
34+
LINE 1: SELECT casttestfunc('foo'::text);
35+
^
36+
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
37+
SELECT casttestfunc('foo'::text::casttesttype); -- should work
38+
casttestfunc
39+
--------------
40+
1
41+
(1 row)
42+
43+
DROP CAST (text AS casttesttype); -- cleanup
44+
-- Try IMPLICIT binary coercion cast
45+
CREATE CAST (text AS casttesttype) WITHOUT FUNCTION AS IMPLICIT;
46+
SELECT casttestfunc('foo'::text); -- Should work now
47+
casttestfunc
48+
--------------
49+
1
50+
(1 row)
51+
52+
-- Try I/O conversion cast.
53+
SELECT 1234::int4::casttesttype; -- No cast yet, should fail
54+
ERROR: cannot cast type integer to casttesttype
55+
LINE 1: SELECT 1234::int4::casttesttype;
56+
^
57+
CREATE CAST (int4 AS casttesttype) WITH INOUT;
58+
SELECT 1234::int4::casttesttype; -- Should work now
59+
casttesttype
60+
--------------
61+
1234
62+
(1 row)
63+
64+
DROP CAST (int4 AS casttesttype);
65+
-- Try cast with a function
66+
CREATE FUNCTION int4_casttesttype(int4) RETURNS casttesttype LANGUAGE SQL AS
67+
$$ SELECT ('foo'::text || $1::text)::casttesttype; $$;
68+
CREATE CAST (int4 AS casttesttype) WITH FUNCTION int4_casttesttype(int4) AS IMPLICIT;
69+
SELECT 1234::int4::casttesttype; -- Should work now
70+
casttesttype
71+
--------------
72+
foo1234
73+
(1 row)
74+

‎src/test/regress/parallel_schedule

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ----------
2-
# $PostgreSQL: pgsql/src/test/regress/parallel_schedule,v 1.49 2008/10/04 21:56:55 tgl Exp $
2+
# $PostgreSQL: pgsql/src/test/regress/parallel_schedule,v 1.50 2008/10/31 09:17:16 heikki Exp $
33
#
44
# By convention, we put no more than twenty tests in any one parallel group;
55
# this limits the number of connections needed to run the tests.
@@ -47,7 +47,7 @@ test: copy copyselect
4747
# ----------
4848
# Another group of parallel tests
4949
# ----------
50-
test: constraints triggers create_misc create_aggregate create_operator inherit vacuum drop_if_exists
50+
test: constraints triggers create_misc create_aggregate create_operator inherit vacuum drop_if_exists create_cast
5151

5252
# Depends on the above
5353
test: create_index create_view

‎src/test/regress/serial_schedule

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/src/test/regress/serial_schedule,v 1.46 2008/10/04 21:56:55 tgl Exp $
1+
# $PostgreSQL: pgsql/src/test/regress/serial_schedule,v 1.47 2008/10/31 09:17:16 heikki Exp $
22
# This should probably be in an order similar to parallel_schedule.
33
test: boolean
44
test: char
@@ -48,6 +48,7 @@ test: create_function_1
4848
test: create_type
4949
test: create_table
5050
test: create_function_2
51+
test: create_cast
5152
test: copy
5253
test: copyselect
5354
test: constraints

‎src/test/regress/sql/create_cast.sql

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--
2+
-- CREATE_CAST
3+
--
4+
5+
-- Create some types to test with
6+
CREATETYPEcasttesttype;
7+
8+
CREATEFUNCTIONcasttesttype_in(cstring)
9+
RETURNS casttesttype
10+
AS'textin'
11+
LANGUAGE internal STRICT;
12+
CREATEFUNCTIONcasttesttype_out(casttesttype)
13+
RETURNS cstring
14+
AS'textout'
15+
LANGUAGE internal STRICT;
16+
17+
CREATETYPEcasttesttype (
18+
internallength= variable,
19+
input= casttesttype_in,
20+
output= casttesttype_out,
21+
alignment= int4
22+
);
23+
24+
-- a dummy function to test with
25+
CREATEFUNCTIONcasttestfunc(casttesttype) RETURNS int4 LANGUAGE SQLAS
26+
$$SELECT1; $$;
27+
28+
SELECT casttestfunc('foo'::text);-- fails, as there's no cast
29+
30+
-- Try binary coercion cast
31+
CREATE CAST (textAS casttesttype) WITHOUT FUNCTION;
32+
SELECT casttestfunc('foo'::text);-- doesn't work, as the cast is explicit
33+
SELECT casttestfunc('foo'::text::casttesttype);-- should work
34+
DROP CAST (textAS casttesttype);-- cleanup
35+
36+
-- Try IMPLICIT binary coercion cast
37+
CREATE CAST (textAS casttesttype) WITHOUT FUNCTIONAS IMPLICIT;
38+
SELECT casttestfunc('foo'::text);-- Should work now
39+
40+
-- Try I/O conversion cast.
41+
SELECT1234::int4::casttesttype;-- No cast yet, should fail
42+
43+
CREATE CAST (int4AS casttesttype) WITH INOUT;
44+
SELECT1234::int4::casttesttype;-- Should work now
45+
46+
DROP CAST (int4AS casttesttype);
47+
48+
-- Try cast with a function
49+
50+
CREATEFUNCTIONint4_casttesttype(int4) RETURNS casttesttype LANGUAGE SQLAS
51+
$$SELECT ('foo'::text|| $1::text)::casttesttype; $$;
52+
53+
CREATE CAST (int4AS casttesttype) WITH FUNCTION int4_casttesttype(int4)AS IMPLICIT;
54+
SELECT1234::int4::casttesttype;-- Should work now

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp