6
-- Note: widget_in/out were created in create_function_1, without any
7
-- prior shell-type creation. These commands therefore complete a test
8
-- of the "old style" approach of making the functions first.
14
typmod_in = numerictypmodin,
15
typmod_out = numerictypmodout,
19
CREATE TYPE city_budget (
24
category = 'x', -- just to verify the system will take it
25
preferred = true -- ditto
28
-- Test creation and destruction of shell types
30
CREATE TYPE shell; -- fail, type already present
32
DROP TYPE shell; -- fail, type not exist
35
-- Test type-related default values (broken in releases before PG 7.2)
37
-- This part of the test also exercises the "new style" approach of making
38
-- a shell type and then filling it in.
41
CREATE TYPE text_w_default;
43
-- Make dummy I/O routines using the existing internal support for int4, text
44
CREATE FUNCTION int42_in(cstring)
47
LANGUAGE internal STRICT;
48
CREATE FUNCTION int42_out(int42)
51
LANGUAGE internal STRICT;
52
CREATE FUNCTION text_w_default_in(cstring)
53
RETURNS text_w_default
55
LANGUAGE internal STRICT;
56
CREATE FUNCTION text_w_default_out(text_w_default)
59
LANGUAGE internal STRICT;
70
CREATE TYPE text_w_default (
71
internallength = variable,
72
input = text_w_default_in,
73
output = text_w_default_out,
78
CREATE TABLE default_test (f1 text_w_default, f2 int42);
80
INSERT INTO default_test DEFAULT VALUES;
82
SELECT * FROM default_test;
84
-- Test stand-alone composite type
86
CREATE TYPE default_test_row AS (f1 text_w_default, f2 int42);
88
CREATE FUNCTION get_default_test() RETURNS SETOF default_test_row AS '
89
SELECT * FROM default_test;
92
SELECT * FROM get_default_test();
95
COMMENT ON TYPE bad IS 'bad comment';
96
COMMENT ON TYPE default_test_row IS 'good comment';
97
COMMENT ON TYPE default_test_row IS NULL;
99
-- Check shell type create for existing types
100
CREATE TYPE text_w_default; -- should fail
102
DROP TYPE default_test_row CASCADE;
104
DROP TABLE default_test;
106
-- Check usage of typmod with a user-defined type
107
-- (we have borrowed numeric's typmod functions)
109
CREATE TEMP TABLE mytab (foo widget(42,13,7)); -- should fail
110
CREATE TEMP TABLE mytab (foo widget(42,13));
112
SELECT format_type(atttypid,atttypmod) FROM pg_attribute
113
WHERE attrelid = 'mytab'::regclass AND attnum > 0;