~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-security

« back to all changes in this revision

Viewing changes to src/test/regress/sql/create_type.sql

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--
 
2
-- CREATE_TYPE
 
3
--
 
4
 
 
5
--
 
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.
 
9
--
 
10
CREATE TYPE widget (
 
11
   internallength = 24, 
 
12
   input = widget_in,
 
13
   output = widget_out,
 
14
   typmod_in = numerictypmodin,
 
15
   typmod_out = numerictypmodout,
 
16
   alignment = double
 
17
);
 
18
 
 
19
CREATE TYPE city_budget ( 
 
20
   internallength = 16, 
 
21
   input = int44in, 
 
22
   output = int44out, 
 
23
   element = int4,
 
24
   category = 'x',   -- just to verify the system will take it
 
25
   preferred = true  -- ditto
 
26
);
 
27
 
 
28
-- Test creation and destruction of shell types
 
29
CREATE TYPE shell;
 
30
CREATE TYPE shell;   -- fail, type already present
 
31
DROP TYPE shell;
 
32
DROP TYPE shell;     -- fail, type not exist
 
33
 
 
34
--
 
35
-- Test type-related default values (broken in releases before PG 7.2)
 
36
--
 
37
-- This part of the test also exercises the "new style" approach of making
 
38
-- a shell type and then filling it in.
 
39
--
 
40
CREATE TYPE int42;
 
41
CREATE TYPE text_w_default;
 
42
 
 
43
-- Make dummy I/O routines using the existing internal support for int4, text
 
44
CREATE FUNCTION int42_in(cstring)
 
45
   RETURNS int42
 
46
   AS 'int4in'
 
47
   LANGUAGE internal STRICT;
 
48
CREATE FUNCTION int42_out(int42)
 
49
   RETURNS cstring
 
50
   AS 'int4out'
 
51
   LANGUAGE internal STRICT;
 
52
CREATE FUNCTION text_w_default_in(cstring)
 
53
   RETURNS text_w_default
 
54
   AS 'textin'
 
55
   LANGUAGE internal STRICT;
 
56
CREATE FUNCTION text_w_default_out(text_w_default)
 
57
   RETURNS cstring
 
58
   AS 'textout'
 
59
   LANGUAGE internal STRICT;
 
60
 
 
61
CREATE TYPE int42 (
 
62
   internallength = 4,
 
63
   input = int42_in,
 
64
   output = int42_out,
 
65
   alignment = int4,
 
66
   default = 42,
 
67
   passedbyvalue
 
68
);
 
69
 
 
70
CREATE TYPE text_w_default (
 
71
   internallength = variable,
 
72
   input = text_w_default_in,
 
73
   output = text_w_default_out,
 
74
   alignment = int4,
 
75
   default = 'zippo'
 
76
);
 
77
 
 
78
CREATE TABLE default_test (f1 text_w_default, f2 int42);
 
79
 
 
80
INSERT INTO default_test DEFAULT VALUES;
 
81
 
 
82
SELECT * FROM default_test;
 
83
 
 
84
-- Test stand-alone composite type
 
85
 
 
86
CREATE TYPE default_test_row AS (f1 text_w_default, f2 int42);
 
87
 
 
88
CREATE FUNCTION get_default_test() RETURNS SETOF default_test_row AS '
 
89
  SELECT * FROM default_test;
 
90
' LANGUAGE SQL;
 
91
 
 
92
SELECT * FROM get_default_test();
 
93
 
 
94
-- Test comments
 
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;
 
98
 
 
99
-- Check shell type create for existing types
 
100
CREATE TYPE text_w_default;             -- should fail
 
101
 
 
102
DROP TYPE default_test_row CASCADE;
 
103
 
 
104
DROP TABLE default_test;
 
105
 
 
106
-- Check usage of typmod with a user-defined type
 
107
-- (we have borrowed numeric's typmod functions)
 
108
 
 
109
CREATE TEMP TABLE mytab (foo widget(42,13,7));     -- should fail
 
110
CREATE TEMP TABLE mytab (foo widget(42,13));
 
111
 
 
112
SELECT format_type(atttypid,atttypmod) FROM pg_attribute
 
113
WHERE attrelid = 'mytab'::regclass AND attnum > 0;