Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 01c76f7

Browse files
committed
Ok. Updated patch attached.
- domain.patch -> source patch against pgsql in cvs - drop_domain.sgml and create_domain.sgml -> New doc/src/sgml/ref docs - dominfo.txt -> basic domain related queries I used for testing [ ADDED TO /doc] Enables domains of array elements -> CREATE DOMAIN dom int4[3][2]; Uses a typbasetype column to describe the origin of the domain. Copies data to attnotnull rather than processing in execMain(). Some documentation differences from earlier. If this is approved, I'll start working on pg_dump, and a \dD <domain> option in psql, and regression tests. I don't really feel like doing those until the system table structure settles for pg_type. CHECKS when added, will also be copied to to the table attributes. FK Constraints (if I ever figure out how) will be done similarly. Both will lbe handled by MergeDomainAttributes() which is called shortly before MergeAttributes(). Rod Taylor
1 parent 3d9f865 commit 01c76f7

32 files changed

+1660
-270
lines changed

doc/dominfo.txt

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
3+
-- Test Comment / Drop
4+
create domain domaindroptest int4;
5+
comment on domain domaindroptest is 'About to drop this..';
6+
7+
select * from pg_type where typname = 'domaindroptest';
8+
9+
drop domain domaindroptest restrict;
10+
11+
select * from pg_type where typname = 'domaindroptest';
12+
13+
-- TEST Domains.
14+
15+
create domain domainvarchar varchar(5);
16+
create domain domainnumeric numeric(8,2);
17+
create domain domainint4 int4;
18+
create domain domaintext text;
19+
20+
21+
-- Test tables using domains
22+
create table basictest
23+
( testint4 domainint4
24+
, testtext domaintext
25+
, testvarchar domainvarchar
26+
, testnumeric domainnumeric
27+
);
28+
29+
INSERT INTO basictest values ('88', 'haha', 'short', '123.12'); -- Good
30+
INSERT INTO basictest values ('88', 'haha', 'short text', '123.12'); -- Bad varchar
31+
INSERT INTO basictest values ('88', 'haha', 'short', '123.1212'); -- Truncate numeric
32+
select * from basictest;
33+
34+
35+
-- Array Test
36+
create domain domainint4arr int4[1];
37+
create domain domaintextarr text[2][3];
38+
39+
create table arrtest
40+
( testint4arr domainint4arr
41+
, testtextarr domaintextarr
42+
);
43+
INSERT INTO arrtest values ('{2,2}', '{{"a","b"}{"c","d"}}');
44+
INSERT INTO arrtest values ('{{2,2}{2,2}}', '{{"a","b"}}');
45+
INSERT INTO arrtest values ('{2,2}', '{{"a","b"}{"c","d"}{"e"}}');
46+
INSERT INTO arrtest values ('{2,2}', '{{"a"}{"c"}}');
47+
INSERT INTO arrtest values (NULL, '{{"a","b"}{"c","d","e"}}');
48+
49+
50+
create domain dnotnull varchar(15) NOT NULL;
51+
create domain dnull varchar(15) NULL;
52+
53+
create table nulltest
54+
( col1 dnotnull
55+
, col2 dnotnull NULL -- NOT NULL in the domain cannot be overridden
56+
, col3 dnull NOT NULL
57+
, col4 dnull
58+
);
59+
INSERT INTO nulltest DEFAULT VALUES;
60+
INSERT INTO nulltest values ('a', 'b', 'c', 'd'); -- Good
61+
INSERT INTO nulltest values (NULL, 'b', 'c', 'd');
62+
INSERT INTO nulltest values ('a', NULL, 'c', 'd');
63+
INSERT INTO nulltest values ('a', 'b', NULL, 'd');
64+
INSERT INTO nulltest values ('a', 'b', 'c', NULL); -- Good
65+
select * from nulltest;
66+
67+
68+
create domain ddef1 int4 DEFAULT 3;
69+
create domain ddef2 numeric(8,6) DEFAULT '1234.123456789';
70+
-- Type mixing, function returns int8
71+
create domain ddef3 text DEFAULT 5;
72+
create sequence ddef4_seq;
73+
create domain ddef4 int4 DEFAULT nextval(cast('ddef4_seq' as text));
74+
75+
create table defaulttest
76+
( col1 ddef1
77+
, col2 ddef2
78+
, col3 ddef3
79+
, col4 ddef4
80+
, col5 ddef1 NOT NULL DEFAULT NULL
81+
, col6 ddef2 DEFAULT '88.1'
82+
, col7 ddef4 DEFAULT 8000
83+
);
84+
insert into defaulttest default values;
85+
insert into defaulttest default values;
86+
insert into defaulttest default values;
87+
select * from defaulttest;

doc/src/sgml/catalogs.sgml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Documentation of the system catalogs, directed toward PostgreSQL developers
3-
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.31 2002/03/01 22:45:03 petere Exp $
3+
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.32 2002/03/06 20:34:43 momjian Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -2510,6 +2510,53 @@
25102510
</para></entry>
25112511
</row>
25122512

2513+
<row>
2514+
<entry>typbasetype</entry>
2515+
<entry><type>oid</type></entry>
2516+
<entry></entry>
2517+
<entry><para>
2518+
<structfield>typbasetype</structfield> is the type that this one is based
2519+
off of. Normally references the domains parent type, and is 0 otherwise.
2520+
</para></entry>
2521+
</row>
2522+
2523+
<row>
2524+
<entry>typnotnull</entry>
2525+
<entry><type>boolean</type></entry>
2526+
<entry></entry>
2527+
<entry><para>
2528+
<structfield>typnotnull</structfield> represents a NOT NULL
2529+
constraint on a type. Normally used only for domains.
2530+
</para></entry>
2531+
</row>
2532+
2533+
<row>
2534+
<entry>typmod</entry>
2535+
<entry><type>integer</type></entry>
2536+
<entry></entry>
2537+
<entry><para>
2538+
<structfield>typmod</structfield> records type-specific data
2539+
supplied at table creation time (for example, the maximum
2540+
length of a <type>varchar</type> column). It is passed to
2541+
type-specific input and output functions as the third
2542+
argument. The value will generally be -1 for types that do not
2543+
need typmod. This data is copied to
2544+
<structfield>pg_attribute.atttypmod</structfield> on creation
2545+
of a table using a domain as it's field type.
2546+
</para></entry>
2547+
</row>
2548+
2549+
<row>
2550+
<entry>typdefaultbin</entry>
2551+
<entry><type>text</type></entry>
2552+
<entry></entry>
2553+
<entry><para>
2554+
<structfield>typdefaultbin</structfield> is NULL for types without a
2555+
default value. If it's not NULL, it contains the internal string
2556+
representation of the default expression node.
2557+
</para></entry>
2558+
</row>
2559+
25132560
<row>
25142561
<entry>typdefault</entry>
25152562
<entry><type>text</type></entry>

doc/src/sgml/ref/allfiles.sgml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.33 2002/03/01 22:45:07 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.34 2002/03/06 20:34:44 momjian Exp $
33
PostgreSQL documentation
44
Complete list of usable sgml source files in this directory.
55
-->
@@ -52,6 +52,7 @@ Complete list of usable sgml source files in this directory.
5252
<!entity createAggregate system "create_aggregate.sgml">
5353
<!entity createConstraint system "create_constraint.sgml">
5454
<!entity createDatabase system "create_database.sgml">
55+
<!entity createDomain system "create_domain.sgml">
5556
<!entity createFunction system "create_function.sgml">
5657
<!entity createGroup system "create_group.sgml">
5758
<!entity createIndex system "create_index.sgml">
@@ -69,6 +70,7 @@ Complete list of usable sgml source files in this directory.
6970
<!entity delete system "delete.sgml">
7071
<!entity dropAggregate system "drop_aggregate.sgml">
7172
<!entity dropDatabase system "drop_database.sgml">
73+
<!entity dropDomain system "drop_domain.sgml">
7274
<!entity dropFunction system "drop_function.sgml">
7375
<!entity dropGroup system "drop_group.sgml">
7476
<!entity dropIndex system "drop_index.sgml">

doc/src/sgml/ref/comment.sgml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/comment.sgml,v 1.12 2001/12/27 21:36:57 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/comment.sgml,v 1.13 2002/03/06 20:34:44 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -25,15 +25,15 @@ PostgreSQL documentation
2525
<synopsis>
2626
COMMENT ON
2727
[
28-
[ DATABASE | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ] <replaceable class="PARAMETER">object_name</replaceable> |
28+
[ DATABASE | DOMAIN | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ] <replaceable class="PARAMETER">object_name</replaceable> |
2929
COLUMN <replaceable class="PARAMETER">table_name</replaceable>.<replaceable class="PARAMETER">column_name</replaceable> |
3030
AGGREGATE <replaceable class="PARAMETER">agg_name</replaceable> (<replaceable class="PARAMETER">agg_type</replaceable>) |
3131
FUNCTION <replaceable class="PARAMETER">func_name</replaceable> (<replaceable class="PARAMETER">arg1</replaceable>, <replaceable class="PARAMETER">arg2</replaceable>, ...) |
3232
OPERATOR <replaceable class="PARAMETER">op</replaceable> (<replaceable class="PARAMETER">leftoperand_type</replaceable> <replaceable class="PARAMETER">rightoperand_type</replaceable>) |
3333
TRIGGER <replaceable class="PARAMETER">trigger_name</replaceable> ON <replaceable class="PARAMETER">table_name</replaceable>
3434
] IS <replaceable class="PARAMETER">'text'</replaceable>
3535
</synopsis>
36-
36+
3737
<refsect2 id="R2-SQL-COMMENT-1">
3838
<refsect2info>
3939
<date>1999-10-25</date>
@@ -64,7 +64,7 @@ COMMENT ON
6464
</variablelist>
6565
</para>
6666
</refsect2>
67-
67+
6868
<refsect2 id="R2-SQL-COMMENT-2">
6969
<refsect2info>
7070
<date>1998-09-08</date>
@@ -99,7 +99,7 @@ COMMENT
9999
</title>
100100
<para>
101101
<command>COMMENT</command> stores a comment about a database object.
102-
Comments can be
102+
Comments can be
103103
easily retrieved with <command>psql</command>'s
104104
<command>\dd</command>, <command>\d+</command>, or <command>\l+</command>
105105
commands. Other user interfaces to retrieve comments can be built atop
@@ -141,6 +141,7 @@ COMMENT ON mytable IS 'This is my table.';
141141

142142
<programlisting>
143143
COMMENT ON DATABASE my_database IS 'Development Database';
144+
COMMENT ON DOMAIN my_domain IS 'Domains are like abstracted fields';
144145
COMMENT ON INDEX my_index IS 'Enforces uniqueness on employee id';
145146
COMMENT ON RULE my_rule IS 'Logs UPDATES of employee records';
146147
COMMENT ON SEQUENCE my_sequence IS 'Used to generate primary keys';
@@ -155,12 +156,12 @@ COMMENT ON TRIGGER my_trigger ON my_table IS 'Used for R.I.';
155156
</programlisting>
156157
</para>
157158
</refsect1>
158-
159+
159160
<refsect1 id="R1-SQL-COMMENT-3">
160161
<title>
161162
Compatibility
162163
</title>
163-
164+
164165
<refsect2 id="R2-SQL-COMMENT-4">
165166
<refsect2info>
166167
<date>1998-09-08</date>

0 commit comments

Comments
 (0)