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

Commit 64505ed

Browse files
committed
Code review for standalone composite types, query-specified composite
types, SRFs. Not happy with memory management yet, but I'll commit these other changes.
1 parent 7483749 commit 64505ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+847
-755
lines changed

contrib/dbsize/dbsize.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ relation_size(PG_FUNCTION_ARGS)
112112

113113
relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname,
114114
"relation_size"));
115-
relation = relation_openrv(relrv, AccessShareLock);
115+
relation = heap_openrv(relrv, AccessShareLock);
116116

117117
relnode = relation->rd_rel->relfilenode;
118118

@@ -140,7 +140,7 @@ relation_size(PG_FUNCTION_ARGS)
140140
segcount++;
141141
}
142142

143-
relation_close(relation, AccessShareLock);
143+
heap_close(relation, AccessShareLock);
144144

145145
PG_RETURN_INT64(totalsize);
146146
}

doc/src/sgml/ref/create_type.sgml

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_type.sgml,v 1.33 2002/08/23 00:33:24 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_type.sgml,v 1.34 2002/08/29 00:17:01 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -32,11 +32,7 @@ CREATE TYPE <replaceable class="parameter">typename</replaceable> ( INPUT = <rep
3232
)
3333

3434
CREATE TYPE <replaceable class="parameter">typename</replaceable> AS
35-
( <replaceable class="PARAMETER">column_definition_list</replaceable> )
36-
37-
where <replaceable class="PARAMETER">column_definition_list</replaceable> can be:
38-
39-
( <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [, ... ] )
35+
( <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [, ... ] )
4036
</synopsis>
4137

4238
<refsect2 id="R2-SQL-CREATETYPE-1">
@@ -216,8 +212,12 @@ CREATE TYPE
216212
type names also must not conflict with table names in the same schema.)
217213
</para>
218214

215+
<refsect2>
216+
<title>Base Types</title>
217+
219218
<para>
220-
The first form of <command>CREATE TYPE</command> requires the
219+
The first form of <command>CREATE TYPE</command> creates a new base type
220+
(scalar type). It requires the
221221
registration of two functions (using CREATE FUNCTION) before defining the
222222
type. The representation of a new base type is determined by
223223
<replaceable class="parameter">input_function</replaceable>, which
@@ -338,20 +338,27 @@ CREATE TYPE
338338
a row fit, but they will be kept in the main table preferentially over
339339
<literal>extended</literal> and <literal>external</literal> items.)
340340
</para>
341+
</refsect2>
342+
343+
<refsect2>
344+
<title>Composite Types</title>
341345

342346
<para>
343-
The second form of <command>CREATE TYPE</command> requires a column
344-
definition list in the form ( <replaceable class="PARAMETER">column_name</replaceable>
345-
<replaceable class="PARAMETER">data_type</replaceable> [, ... ] ). This
346-
creates a composite type, similar to that of a TABLE or VIEW relation.
347-
A stand-alone composite type is useful as the return type of FUNCTION.
347+
The second form of <command>CREATE TYPE</command>
348+
creates a composite type.
349+
The composite type is specified by a list of column names and datatypes.
350+
This is essentially the same as the row type
351+
of a table, but using <command>CREATE TYPE</command> avoids the need to
352+
create an actual table when all that is wanted is to define a type.
353+
A stand-alone composite type is useful as the return type of a function.
348354
</para>
355+
</refsect2>
349356

350357
<refsect2>
351358
<title>Array Types</title>
352359

353360
<para>
354-
Whenever a user-defined data type is created,
361+
Whenever a user-defined base data type is created,
355362
<productname>PostgreSQL</productname> automatically creates an
356363
associated array type, whose name consists of the base type's
357364
name prepended with an underscore. The parser understands this
@@ -436,8 +443,8 @@ CREATE TABLE big_objs (id int4, obj bigobj);
436443
This example creates a composite type and uses it in
437444
a table function definition:
438445
<programlisting>
439-
CREATE TYPE compfoo AS (f1 int, f2 int);
440-
CREATE FUNCTION getfoo() RETURNS SETOF compfoo AS 'SELECT fooid, foorefid FROM foo' LANGUAGE SQL;
446+
CREATE TYPE compfoo AS (f1 int, f2 text);
447+
CREATE FUNCTION getfoo() RETURNS SETOF compfoo AS 'SELECT fooid, fooname FROM foo' LANGUAGE SQL;
441448
</programlisting>
442449
</para>
443450
</refsect1>

doc/src/sgml/ref/select.sgml

Lines changed: 74 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.57 2002/08/28 14:35:37 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.58 2002/08/29 00:17:01 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -40,10 +40,10 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
4040
( <replaceable class="PARAMETER">select</replaceable> )
4141
[ AS ] <replaceable class="PARAMETER">alias</replaceable> [ ( <replaceable class="PARAMETER">column_alias_list</replaceable> ) ]
4242
|
43-
<replaceable class="PARAMETER">table_function_name</replaceable> ( [ <replaceable class="parameter">argtype</replaceable> [, ...] ] )
43+
<replaceable class="PARAMETER">table_function_name</replaceable> ( [ <replaceable class="parameter">argument</replaceable> [, ...] ] )
4444
[ AS ] <replaceable class="PARAMETER">alias</replaceable> [ ( <replaceable class="PARAMETER">column_alias_list</replaceable> | <replaceable class="PARAMETER">column_definition_list</replaceable> ) ]
4545
|
46-
<replaceable class="PARAMETER">table_function_name</replaceable> ( [ <replaceable class="parameter">argtype</replaceable> [, ...] ] )
46+
<replaceable class="PARAMETER">table_function_name</replaceable> ( [ <replaceable class="parameter">argument</replaceable> [, ...] ] )
4747
AS ( <replaceable class="PARAMETER">column_definition_list</replaceable> )
4848
|
4949
<replaceable class="PARAMETER">from_item</replaceable> [ NATURAL ] <replaceable class="PARAMETER">join_type</replaceable> <replaceable class="PARAMETER">from_item</replaceable>
@@ -142,10 +142,14 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
142142
<term><replaceable class="PARAMETER">alias</replaceable></term>
143143
<listitem>
144144
<para>
145-
A substitute name for the preceding
146-
<replaceable class="PARAMETER">table_name</replaceable>.
145+
A substitute name for the FROM item containing the alias.
147146
An alias is used for brevity or to eliminate ambiguity for self-joins
148-
(where the same table is scanned multiple times). If an alias is
147+
(where the same table is scanned multiple times). When an alias
148+
is provided, it completely hides the actual name of the table or
149+
table function; for example given <literal>FROM foo AS f</>, the
150+
remainder of the SELECT must refer to this FROM item as <literal>f</>
151+
not <literal>foo</>.
152+
If an alias is
149153
written, a column alias list can also be written to provide
150154
substitute names for one or more columns of the table.
151155
</para>
@@ -172,12 +176,15 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
172176
A table function can appear in the FROM clause. This acts as though
173177
its output were created as a temporary table for the duration of
174178
this single SELECT command. An alias may also be used. If an alias is
175-
written, a column alias list can also be written to provide substitute names
176-
for one or more columns of the table function. If the table function has been
177-
defined as returning the RECORD data type, an alias, or the keyword AS, must
178-
also be present, followed by a column definition list in the form
179-
( <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [, ... ] ).
180-
The column definition list must match the actual number and types returned by the function.
179+
written, a column alias list can also be written to provide substitute
180+
names for one or more columns of the table function. If the table
181+
function has been defined as returning the <type>record</> data type,
182+
an alias, or the keyword <literal>AS</>, must be present, followed by
183+
a column definition list in the form ( <replaceable
184+
class="PARAMETER">column_name</replaceable> <replaceable
185+
class="PARAMETER">data_type</replaceable> [, ... ] ).
186+
The column definition list must match the actual number and types
187+
of columns returned by the function.
181188
</para>
182189
</listitem>
183190
</varlistentry>
@@ -395,7 +402,7 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
395402
this was the default result, and adding sub-tables was done
396403
by appending <command>*</command> to the table name.
397404
This old behavior is available via the command
398-
<command>SET SQL_Inheritance TO OFF;</command>
405+
<command>SET SQL_Inheritance TO OFF</command>.
399406
</para>
400407

401408
<para>
@@ -406,16 +413,22 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
406413
</para>
407414

408415
<para>
409-
A FROM item can be a table function (i.e. a function that returns
410-
multiple rows and columns). When a table function is created, it may
411-
be defined to return a named scalar or composite data type (an existing
412-
scalar data type, or a table or view name), or it may be defined to return
413-
a RECORD data type. When a table function is defined to return RECORD, it
414-
must be followed in the FROM clause by an alias, or the keyword AS alone,
415-
and then by a parenthesized list of column names and types. This provides
416-
a query-time composite type definition. The FROM clause composite type
417-
must match the actual composite type returned from the function or an
418-
ERROR will be generated.
416+
A FROM item can be a table function (typically, a function that returns
417+
multiple rows and/or columns, though actually any function can be used).
418+
The function is invoked with the given argument value(s), and then its
419+
output is scanned as though it were a table.
420+
</para>
421+
422+
<para>
423+
In some cases it is useful to define table functions that can return
424+
different column sets depending on how they are invoked. To support this,
425+
the table function can be declared as returning the pseudo-type
426+
<type>record</>. When such a function is used in FROM, it must be
427+
followed by an alias, or the keyword <literal>AS</> alone,
428+
and then by a parenthesized list of column names and types. This provides
429+
a query-time composite type definition. The composite type definition
430+
must match the actual composite type returned from the function, or an
431+
error will be reported at run-time.
419432
</para>
420433

421434
<para>
@@ -827,6 +840,38 @@ SELECT name FROM distributors ORDER BY code;
827840
unless ORDER BY is used to constrain the order.
828841
</para>
829842
</refsect2>
843+
844+
<refsect2 id="SQL-FOR-UPDATE">
845+
<refsect2info>
846+
<date>2002-08-28</date>
847+
</refsect2info>
848+
<title id="sql-for-update-title">
849+
FOR UPDATE Clause
850+
</title>
851+
<para>
852+
<synopsis>
853+
FOR UPDATE [ OF <replaceable class="PARAMETER">tablename</replaceable> [, ...] ]
854+
</synopsis>
855+
</para>
856+
857+
<para>
858+
FOR UPDATE causes the rows retrieved by the query to be locked as though
859+
for update. This prevents them from being modified or deleted by other
860+
transactions until the current transaction ends.
861+
</para>
862+
863+
<para>
864+
If specific tables are named in FOR UPDATE, then only rows coming from
865+
those tables are locked.
866+
</para>
867+
868+
<para>
869+
FOR UPDATE cannot be used in contexts where returned rows can't be clearly
870+
identified with individual table rows; for example it can't be used with
871+
aggregation.
872+
</para>
873+
</refsect2>
874+
830875
</refsect1>
831876

832877
<refsect1 id="R1-SQL-SELECT-2">
@@ -1019,8 +1064,7 @@ SELECT * FROM distributors_2(111) AS (f1 int, f2 text);
10191064
<productname>PostgreSQL</productname> allows one to omit
10201065
the <command>FROM</command> clause from a query. This feature
10211066
was retained from the original PostQuel query language. It has
1022-
a straightforward use to compute the results of simple constant
1023-
expressions:
1067+
a straightforward use to compute the results of simple expressions:
10241068

10251069
<programlisting>
10261070
SELECT 2+2;
@@ -1062,6 +1106,11 @@ and later will warn if the implicit-FROM feature is used in a query that also
10621106
contains an explicit FROM clause.
10631107

10641108
</para>
1109+
1110+
<para>
1111+
The table-function feature is a <productname>PostgreSQL</productname>
1112+
extension.
1113+
</para>
10651114
</refsect2>
10661115

10671116
<refsect2 id="R2-SQL-SELECT-5">

doc/src/sgml/ref/select_into.sgml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select_into.sgml,v 1.19 2002/08/28 14:35:37 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select_into.sgml,v 1.20 2002/08/29 00:17:01 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -29,20 +29,9 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="PARAMETER">expression</replac
2929
[ HAVING <replaceable class="PARAMETER">condition</replaceable> [, ...] ]
3030
[ { UNION | INTERSECT | EXCEPT } [ ALL ] <replaceable class="PARAMETER">select</replaceable> ]
3131
[ ORDER BY <replaceable class="PARAMETER">expression</replaceable> [ ASC | DESC | USING <replaceable class="PARAMETER">operator</replaceable> ] [, ...] ]
32-
[ LIMIT [ <replaceable class="PARAMETER">start</replaceable> , ] { <replaceable class="PARAMETER">count</replaceable> | ALL } ]
32+
[ LIMIT { <replaceable class="PARAMETER">count</replaceable> | ALL } ]
3333
[ OFFSET <replaceable class="PARAMETER">start</replaceable> ]
3434
[ FOR UPDATE [ OF <replaceable class="PARAMETER">tablename</replaceable> [, ...] ] ]
35-
36-
where <replaceable class="PARAMETER">from_item</replaceable> can be:
37-
38-
[ ONLY ] <replaceable class="PARAMETER">table_name</replaceable> [ * ]
39-
[ [ AS ] <replaceable class="PARAMETER">alias</replaceable> [ ( <replaceable class="PARAMETER">column_alias_list</replaceable> ) ] ]
40-
|
41-
( <replaceable class="PARAMETER">select</replaceable> )
42-
[ AS ] <replaceable class="PARAMETER">alias</replaceable> [ ( <replaceable class="PARAMETER">column_alias_list</replaceable> ) ]
43-
|
44-
<replaceable class="PARAMETER">from_item</replaceable> [ NATURAL ] <replaceable class="PARAMETER">join_type</replaceable> <replaceable class="PARAMETER">from_item</replaceable>
45-
[ ON <replaceable class="PARAMETER">join_condition</replaceable> | USING ( <replaceable class="PARAMETER">join_column_list</replaceable> ) ]
4635
</synopsis>
4736

4837
<refsect2 id="R2-SQL-SELECTINTO-1">

doc/src/sgml/release.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.152 2002/08/27 04:55:07 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.153 2002/08/29 00:17:01 tgl Exp $
33
-->
44

55
<appendix id="release">
@@ -26,6 +26,7 @@ worries about funny characters.
2626
<literallayout><![CDATA[
2727
PREPARE statement allows caching query plans for interactive statements
2828
Type OPAQUE is now deprecated in favor of pseudo-types cstring, trigger, etc
29+
Standalone composite types can now be created with CREATE TYPE
2930
Files larger than 2 GB are now supported (if supported by the operating system)
3031
SERIAL no longer implies UNIQUE; specify explicitly if index is wanted
3132
pg_dump -n and -N options have been removed. The new behavior is like -n but knows about key words.

0 commit comments

Comments
 (0)