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

Commit 0ad9abe

Browse files
committed
Improve discussion of %TYPE and %ROWTYPE.
1 parent 1c1eb0f commit 0ad9abe

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

doc/src/sgml/plsql.sgml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.29 2001/05/08 02:53:24 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.30 2001/05/11 06:10:44 tgl Exp $
33
-->
44

55
<chapter id="plpgsql">
@@ -396,12 +396,13 @@ user_id CONSTANT INTEGER := 10;
396396
</sect3>
397397

398398
<sect3 id="plpgsql-description-passed-vars">
399-
<title>Variables Passed to Functions</title>
399+
<title>Parameters Passed to Functions</title>
400400

401401
<para>
402-
Variables passed to functions are named with the identifiers
402+
Parameters passed to functions are named with the identifiers
403403
<literal>$1</literal>, <literal>$2</literal>,
404-
etc. (maximum is 16). Some examples:
404+
etc. Optionally, aliases can be declared for the <literal>$n</literal>
405+
parameter names for increased readability. Some examples:
405406
<programlisting>
406407
CREATE FUNCTION sales_tax(REAL) RETURNS REAL AS '
407408
DECLARE
@@ -437,7 +438,7 @@ END;
437438
<variablelist>
438439
<varlistentry>
439440
<term>
440-
%TYPE
441+
<replaceable>variable</replaceable>%TYPE
441442
</term>
442443
<listitem>
443444
<para>
@@ -447,9 +448,9 @@ END;
447448
values. For example, let's say you have a column
448449
named <type>user_id</type> in your
449450
<type>users</type> table. To declare a variable with
450-
the same datatype as users you do:
451+
the same datatype as users.user_id you write:
451452
<programlisting>
452-
user_id users.user_id%TYPE;
453+
user_id users.user_id%TYPE;
453454
</programlisting>
454455
</para>
455456

@@ -467,30 +468,31 @@ user_id users.user_id%TYPE;
467468

468469
<varlistentry>
469470
<term>
470-
<replaceable>name</replaceable> <replaceable>table</replaceable>%ROWTYPE;
471+
<replaceable>table</replaceable>%ROWTYPE
471472
</term>
472473
<listitem>
473474
<para>
474-
Declares a row with the structure of the given
475-
table. <replaceable>table</replaceable> must be an existing
475+
<type>%ROWTYPE</type> provides the composite datatype corresponding
476+
to a whole row of the specified table.
477+
<replaceable>table</replaceable> must be an existing
476478
table or view name of the database. The fields of the row are
477479
accessed in the dot notation. Parameters to a function can be
478480
composite types (complete table rows). In that case, the
479-
corresponding identifier $n will be a rowtype, but it must be
480-
aliased using the ALIAS command described above.
481+
corresponding identifier $n will be a rowtype, and fields can
482+
be selected from it, for example <literal>$1.user_id</literal>.
481483
</para>
482484

483485
<para>
484-
Only the user attributes of a table row are accessible in the
485-
row, no OID or other system attributes (because the row could
486-
be from a view). The fields of the rowtype inherit the
486+
Only the user-defined attributes of a table row are accessible in a
487+
rowtype variable, not OID or other system attributes (because the
488+
row could be from a view). The fields of the rowtype inherit the
487489
table's field sizes or precision for <type>char()</type>
488490
etc. data types.
489491
</para>
490492
<programlisting>
491493
DECLARE
492494
users_rec users%ROWTYPE;
493-
user_id users%TYPE;
495+
user_id users.user_id%TYPE;
494496
BEGIN
495497
user_id := users_rec.user_id;
496498
...

0 commit comments

Comments
 (0)