5 -- Note: widget_in/out were created in create_function_1, without any
6 -- prior shell-type creation. These commands therefore complete a test
7 -- of the "old style" approach of making the functions first.
13 typmod_in = numerictypmodin,
14 typmod_out = numerictypmodout,
17 CREATE TYPE city_budget (
22 category = 'x', -- just to verify the system will take it
23 preferred = true -- ditto
25 -- Test creation and destruction of shell types
27 CREATE TYPE shell; -- fail, type already present
28 ERROR: type "shell" already exists
30 DROP TYPE shell; -- fail, type not exist
31 ERROR: type "shell" does not exist
33 -- Test type-related default values (broken in releases before PG 7.2)
35 -- This part of the test also exercises the "new style" approach of making
36 -- a shell type and then filling it in.
39 CREATE TYPE text_w_default;
40 -- Make dummy I/O routines using the existing internal support for int4, text
41 CREATE FUNCTION int42_in(cstring)
44 LANGUAGE internal STRICT;
45 NOTICE: return type int42 is only a shell
46 CREATE FUNCTION int42_out(int42)
49 LANGUAGE internal STRICT;
50 NOTICE: argument type int42 is only a shell
51 CREATE FUNCTION text_w_default_in(cstring)
52 RETURNS text_w_default
54 LANGUAGE internal STRICT;
55 NOTICE: return type text_w_default is only a shell
56 CREATE FUNCTION text_w_default_out(text_w_default)
59 LANGUAGE internal STRICT;
60 NOTICE: argument type text_w_default is only a shell
69 CREATE TYPE text_w_default (
70 internallength = variable,
71 input = text_w_default_in,
72 output = text_w_default_out,
76 CREATE TABLE default_test (f1 text_w_default, f2 int42);
77 INSERT INTO default_test DEFAULT VALUES;
78 SELECT * FROM default_test;
84 -- Test stand-alone composite type
85 CREATE TYPE default_test_row AS (f1 text_w_default, f2 int42);
86 CREATE FUNCTION get_default_test() RETURNS SETOF default_test_row AS '
87 SELECT * FROM default_test;
89 SELECT * FROM get_default_test();
96 COMMENT ON TYPE bad IS 'bad comment';
97 ERROR: type "bad" does not exist
98 COMMENT ON TYPE default_test_row IS 'good comment';
99 COMMENT ON TYPE default_test_row IS NULL;
100 COMMENT ON COLUMN default_test_row.nope IS 'bad comment';
101 ERROR: column "nope" of relation "default_test_row" does not exist
102 COMMENT ON COLUMN default_test_row.f1 IS 'good comment';
103 COMMENT ON COLUMN default_test_row.f1 IS NULL;
104 -- Check shell type create for existing types
105 CREATE TYPE text_w_default; -- should fail
106 ERROR: type "text_w_default" already exists
107 DROP TYPE default_test_row CASCADE;
108 NOTICE: drop cascades to function get_default_test()
109 DROP TABLE default_test;
110 -- Check usage of typmod with a user-defined type
111 -- (we have borrowed numeric's typmod functions)
112 CREATE TEMP TABLE mytab (foo widget(42,13,7)); -- should fail
113 ERROR: invalid NUMERIC type modifier
114 LINE 1: CREATE TEMP TABLE mytab (foo widget(42,13,7));
116 CREATE TEMP TABLE mytab (foo widget(42,13));
117 SELECT format_type(atttypid,atttypmod) FROM pg_attribute
118 WHERE attrelid = 'mytab'::regclass AND attnum > 0;