Flip the default typispreferred setting from true to false. This affects
[PostgreSQL.git] / src / test / regress / expected / create_type.out
blob72556a88f819e27fd90fab4687ef99525448a748
1 --
2 -- CREATE_TYPE
3 --
4 --
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.
8 --
9 CREATE TYPE widget (
10    internallength = 24, 
11    input = widget_in,
12    output = widget_out,
13    typmod_in = numerictypmodin,
14    typmod_out = numerictypmodout,
15    alignment = double
17 CREATE TYPE city_budget ( 
18    internallength = 16, 
19    input = int44in, 
20    output = int44out, 
21    element = int4,
22    category = 'x',   -- just to verify the system will take it
23    preferred = true  -- ditto
25 -- Test creation and destruction of shell types
26 CREATE TYPE shell;
27 CREATE TYPE shell;   -- fail, type already present
28 ERROR:  type "shell" already exists
29 DROP TYPE shell;
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.
38 CREATE TYPE int42;
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)
42    RETURNS int42
43    AS 'int4in'
44    LANGUAGE internal STRICT;
45 NOTICE:  return type int42 is only a shell
46 CREATE FUNCTION int42_out(int42)
47    RETURNS cstring
48    AS 'int4out'
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
53    AS 'textin'
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)
57    RETURNS cstring
58    AS 'textout'
59    LANGUAGE internal STRICT;
60 NOTICE:  argument type text_w_default is only a shell
61 CREATE TYPE int42 (
62    internallength = 4,
63    input = int42_in,
64    output = int42_out,
65    alignment = int4,
66    default = 42,
67    passedbyvalue
69 CREATE TYPE text_w_default (
70    internallength = variable,
71    input = text_w_default_in,
72    output = text_w_default_out,
73    alignment = int4,
74    default = 'zippo'
76 CREATE TABLE default_test (f1 text_w_default, f2 int42);
77 INSERT INTO default_test DEFAULT VALUES;
78 SELECT * FROM default_test;
79   f1   | f2 
80 -------+----
81  zippo | 42
82 (1 row)
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;
88 ' LANGUAGE SQL;
89 SELECT * FROM get_default_test();
90   f1   | f2 
91 -------+----
92  zippo | 42
93 (1 row)
95 -- Test comments
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 -- Check shell type create for existing types
101 CREATE TYPE text_w_default;             -- should fail
102 ERROR:  type "text_w_default" already exists
103 DROP TYPE default_test_row CASCADE;
104 NOTICE:  drop cascades to function get_default_test()
105 DROP TABLE default_test;
106 -- Check usage of typmod with a user-defined type
107 -- (we have borrowed numeric's typmod functions)
108 CREATE TEMP TABLE mytab (foo widget(42,13,7));     -- should fail
109 ERROR:  invalid NUMERIC type modifier
110 CREATE TEMP TABLE mytab (foo widget(42,13));
111 SELECT format_type(atttypid,atttypmod) FROM pg_attribute
112 WHERE attrelid = 'mytab'::regclass AND attnum > 0;
113   format_type  
114 ---------------
115  widget(42,13)
116 (1 row)