2000-01-05 18:31:08 +01:00
|
|
|
--
|
|
|
|
-- CREATE_TYPE
|
|
|
|
--
|
|
|
|
CREATE TYPE widget (
|
|
|
|
internallength = 24,
|
Major patch from Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
OK, here are a passel of patches for the geometric data types.
These add a "circle" data type, new operators and functions
for the existing data types, and change the default formats
for some of the existing types to make them consistant with
each other. Current formatting conventions (e.g. compatible
with v6.0 to allow dump/reload) are supported, but the new
conventions should be an improvement and we can eventually
drop the old conventions entirely.
For example, there are two kinds of paths (connected line segments),
open and closed, and the old format was
'(1,2,1,2,3,4)' for a closed path with two points (1,2) and (3,4)
'(0,2,1,2,3,4)' for an open path with two points (1,2) and (3,4)
Pretty arcane, huh? The new format for paths is
'((1,2),(3,4))' for a closed path with two points (1,2) and (3,4)
'[(1,2),(3,4)]' for an open path with two points (1,2) and (3,4)
For polygons, the old convention is
'(0,4,2,0,4,3)' for a triangle with points at (0,0),(4,4), and (2,3)
and the new convention is
'((0,0),(4,4),(2,3))' for a triangle with points at (0,0),(4,4), and (2,3)
Other data types which are also represented as lists of points
(e.g. boxes, line segments, and polygons) have similar representations
(they surround each point with parens).
For v6.1, any format which can be interpreted as the old style format
is decoded as such; we can remove that backwards compatibility but ugly
convention for v7.0. This will allow dump/reloads from v6.0.
These include some updates to the regression test files to change the test
for creating a data type from "circle" to "widget" to keep the test from
trashing the new builtin circle type.
1997-04-22 19:35:09 +02:00
|
|
|
input = widget_in,
|
|
|
|
output = widget_out,
|
1997-04-05 23:26:00 +02:00
|
|
|
alignment = double
|
|
|
|
);
|
2000-01-05 18:31:08 +01:00
|
|
|
CREATE TYPE city_budget (
|
|
|
|
internallength = 16,
|
|
|
|
input = int44in,
|
|
|
|
output = int44out,
|
1997-04-05 23:26:00 +02:00
|
|
|
element = int4
|
|
|
|
);
|
2001-09-06 04:07:42 +02:00
|
|
|
-- Test type-related default values (broken in releases before PG 7.2)
|
2002-08-22 02:01:51 +02:00
|
|
|
-- Make dummy I/O routines using the existing internal support for int4, text
|
|
|
|
CREATE FUNCTION int42_in(cstring)
|
|
|
|
RETURNS int42
|
|
|
|
AS 'int4in'
|
2006-02-27 17:09:50 +01:00
|
|
|
LANGUAGE internal STRICT;
|
2003-07-28 02:09:16 +02:00
|
|
|
NOTICE: type "int42" is not yet defined
|
2003-07-19 01:20:33 +02:00
|
|
|
DETAIL: Creating a shell type definition.
|
2002-08-22 02:01:51 +02:00
|
|
|
CREATE FUNCTION int42_out(int42)
|
|
|
|
RETURNS cstring
|
|
|
|
AS 'int4out'
|
2006-02-27 17:09:50 +01:00
|
|
|
LANGUAGE internal STRICT;
|
2003-07-19 01:20:33 +02:00
|
|
|
NOTICE: argument type int42 is only a shell
|
2002-08-22 02:01:51 +02:00
|
|
|
CREATE FUNCTION text_w_default_in(cstring)
|
|
|
|
RETURNS text_w_default
|
|
|
|
AS 'textin'
|
2006-02-27 17:09:50 +01:00
|
|
|
LANGUAGE internal STRICT;
|
2003-07-28 02:09:16 +02:00
|
|
|
NOTICE: type "text_w_default" is not yet defined
|
2003-07-19 01:20:33 +02:00
|
|
|
DETAIL: Creating a shell type definition.
|
2002-08-22 02:01:51 +02:00
|
|
|
CREATE FUNCTION text_w_default_out(text_w_default)
|
|
|
|
RETURNS cstring
|
|
|
|
AS 'textout'
|
2006-02-27 17:09:50 +01:00
|
|
|
LANGUAGE internal STRICT;
|
2003-07-19 01:20:33 +02:00
|
|
|
NOTICE: argument type text_w_default is only a shell
|
2001-09-06 04:07:42 +02:00
|
|
|
CREATE TYPE int42 (
|
|
|
|
internallength = 4,
|
2002-08-22 02:01:51 +02:00
|
|
|
input = int42_in,
|
|
|
|
output = int42_out,
|
2001-09-06 04:07:42 +02:00
|
|
|
alignment = int4,
|
|
|
|
default = 42,
|
|
|
|
passedbyvalue
|
|
|
|
);
|
|
|
|
CREATE TYPE text_w_default (
|
|
|
|
internallength = variable,
|
2002-08-22 02:01:51 +02:00
|
|
|
input = text_w_default_in,
|
|
|
|
output = text_w_default_out,
|
2001-09-06 04:07:42 +02:00
|
|
|
alignment = int4,
|
|
|
|
default = 'zippo'
|
|
|
|
);
|
|
|
|
CREATE TABLE default_test (f1 text_w_default, f2 int42);
|
|
|
|
INSERT INTO default_test DEFAULT VALUES;
|
|
|
|
SELECT * FROM default_test;
|
|
|
|
f1 | f2
|
|
|
|
-------+----
|
|
|
|
zippo | 42
|
|
|
|
(1 row)
|
|
|
|
|
2002-08-15 18:36:08 +02:00
|
|
|
-- Test stand-alone composite type
|
|
|
|
CREATE TYPE default_test_row AS (f1 text_w_default, f2 int42);
|
|
|
|
CREATE FUNCTION get_default_test() RETURNS SETOF default_test_row AS '
|
|
|
|
SELECT * FROM default_test;
|
|
|
|
' LANGUAGE SQL;
|
|
|
|
SELECT * FROM get_default_test();
|
|
|
|
f1 | f2
|
|
|
|
-------+----
|
|
|
|
zippo | 42
|
|
|
|
(1 row)
|
|
|
|
|
2003-11-21 23:32:49 +01:00
|
|
|
-- Test comments
|
|
|
|
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;
|
2002-08-15 18:36:08 +02:00
|
|
|
DROP TYPE default_test_row CASCADE;
|
2003-07-21 03:59:11 +02:00
|
|
|
NOTICE: drop cascades to function get_default_test()
|
2001-09-06 04:07:42 +02:00
|
|
|
DROP TABLE default_test;
|