summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2006-02-28 22:37:27 +0000
committerTom Lane2006-02-28 22:37:27 +0000
commit8e68d783902b0b47f377efa4a23a04ddeef272a8 (patch)
treedfb6af0332b662faad90a752d63224fe1ba60470 /src/test
parent7f19339cca746753d898651d128ad038b6e1c635 (diff)
Allow the syntax CREATE TYPE foo, with no parameters, to permit explicit
creation of a shell type. This allows a less hacky way of dealing with the mutual dependency between a datatype and its I/O functions: make a shell type, then make the functions, then define the datatype fully. We should fix pg_dump to handle things this way, but this commit just deals with the backend. Martijn van Oosterhout, with some corrections by Tom Lane.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/create_type.out28
-rw-r--r--src/test/regress/sql/create_type.sql21
2 files changed, 45 insertions, 4 deletions
diff --git a/src/test/regress/expected/create_type.out b/src/test/regress/expected/create_type.out
index 4e2d44d5c41..3e2edeb1e0b 100644
--- a/src/test/regress/expected/create_type.out
+++ b/src/test/regress/expected/create_type.out
@@ -1,6 +1,11 @@
--
-- CREATE_TYPE
--
+--
+-- Note: widget_in/out were created in create_function_1, without any
+-- prior shell-type creation. These commands therefore complete a test
+-- of the "old style" approach of making the functions first.
+--
CREATE TYPE widget (
internallength = 24,
input = widget_in,
@@ -13,14 +18,27 @@ CREATE TYPE city_budget (
output = int44out,
element = int4
);
+-- Test creation and destruction of shell types
+CREATE TYPE shell;
+CREATE TYPE shell; -- fail, type already present
+ERROR: type "shell" already exists
+DROP TYPE shell;
+DROP TYPE shell; -- fail, type not exist
+ERROR: type "shell" does not exist
+--
-- Test type-related default values (broken in releases before PG 7.2)
+--
+-- This part of the test also exercises the "new style" approach of making
+-- a shell type and then filling it in.
+--
+CREATE TYPE int42;
+CREATE TYPE text_w_default;
-- Make dummy I/O routines using the existing internal support for int4, text
CREATE FUNCTION int42_in(cstring)
RETURNS int42
AS 'int4in'
LANGUAGE internal STRICT;
-NOTICE: type "int42" is not yet defined
-DETAIL: Creating a shell type definition.
+NOTICE: return type int42 is only a shell
CREATE FUNCTION int42_out(int42)
RETURNS cstring
AS 'int4out'
@@ -30,8 +48,7 @@ CREATE FUNCTION text_w_default_in(cstring)
RETURNS text_w_default
AS 'textin'
LANGUAGE internal STRICT;
-NOTICE: type "text_w_default" is not yet defined
-DETAIL: Creating a shell type definition.
+NOTICE: return type text_w_default is only a shell
CREATE FUNCTION text_w_default_out(text_w_default)
RETURNS cstring
AS 'textout'
@@ -76,6 +93,9 @@ COMMENT ON TYPE bad IS 'bad comment';
ERROR: type "bad" does not exist
COMMENT ON TYPE default_test_row IS 'good comment';
COMMENT ON TYPE default_test_row IS NULL;
+-- Check shell type create for existing types
+CREATE TYPE text_w_default; -- should fail
+ERROR: type "text_w_default" already exists
DROP TYPE default_test_row CASCADE;
NOTICE: drop cascades to function get_default_test()
DROP TABLE default_test;
diff --git a/src/test/regress/sql/create_type.sql b/src/test/regress/sql/create_type.sql
index 66d78c9216b..097d51fc925 100644
--- a/src/test/regress/sql/create_type.sql
+++ b/src/test/regress/sql/create_type.sql
@@ -2,6 +2,11 @@
-- CREATE_TYPE
--
+--
+-- Note: widget_in/out were created in create_function_1, without any
+-- prior shell-type creation. These commands therefore complete a test
+-- of the "old style" approach of making the functions first.
+--
CREATE TYPE widget (
internallength = 24,
input = widget_in,
@@ -16,7 +21,20 @@ CREATE TYPE city_budget (
element = int4
);
+-- Test creation and destruction of shell types
+CREATE TYPE shell;
+CREATE TYPE shell; -- fail, type already present
+DROP TYPE shell;
+DROP TYPE shell; -- fail, type not exist
+
+--
-- Test type-related default values (broken in releases before PG 7.2)
+--
+-- This part of the test also exercises the "new style" approach of making
+-- a shell type and then filling it in.
+--
+CREATE TYPE int42;
+CREATE TYPE text_w_default;
-- Make dummy I/O routines using the existing internal support for int4, text
CREATE FUNCTION int42_in(cstring)
@@ -74,6 +92,9 @@ COMMENT ON TYPE bad IS 'bad comment';
COMMENT ON TYPE default_test_row IS 'good comment';
COMMENT ON TYPE default_test_row IS NULL;
+-- Check shell type create for existing types
+CREATE TYPE text_w_default; -- should fail
+
DROP TYPE default_test_row CASCADE;
DROP TABLE default_test;