diff options
author | Bruce Momjian <bruce@momjian.us> | 2002-06-15 19:34:51 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2002-06-15 19:34:51 +0000 |
commit | eeb1dd506855e72e723fc5e0140d7c813b9ef347 (patch) | |
tree | ae019292699c8b5bc0c1f783870491023c8c19bc /doc/src | |
parent | 240de617fbfebea029c1dc057708d9f0f2431ac5 (diff) | |
download | postgresql-eeb1dd506855e72e723fc5e0140d7c813b9ef347.tar.gz postgresql-eeb1dd506855e72e723fc5e0140d7c813b9ef347.zip |
On Wed, 2002-05-29 at 01:41, Tom Lane wrote:
>
> > Is it a good idea to provide an example (such as the above), or should I
> > just try and describe the behaviour?
>
> Examples are generally good things ...
OK, the attached documentation patch provides some simple examples of
use of tablename as a parameter, %ROWTYPE and %TYPE.
In the end I decided that the documentation is literally correct, but
hard to follow without any examples explicitly showing the use of a
table name as a parameter.
Andrew McMillan
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/plsql.sgml | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/doc/src/sgml/plsql.sgml b/doc/src/sgml/plsql.sgml index b360e91f5c7..91e96c77f06 100644 --- a/doc/src/sgml/plsql.sgml +++ b/doc/src/sgml/plsql.sgml @@ -1,5 +1,5 @@ <!-- -$Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.58 2002/05/03 04:11:07 tgl Exp $ +$Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.59 2002/06/15 19:34:51 momjian Exp $ --> <chapter id="plpgsql"> @@ -371,6 +371,9 @@ END; user_id INTEGER; quantity NUMERIC(5); url VARCHAR; +myrow tablename%ROWTYPE; +myfield tablename.fieldname%TYPE; +arow RECORD; </programlisting> </para> @@ -448,6 +451,15 @@ BEGIN -- Some computations here END; ' LANGUAGE 'plpgsql'; + + +CREATE FUNCTION use_many_fields(tablename) RETURNS TEXT AS ' +DECLARE + in_t ALIAS FOR $1; +BEGIN + RETURN in_t.f1 || in_t.f3 || in_t.f5 || in_t.f7; +END; +' LANGUAGE 'plpgsql'; </programlisting> </para> </sect2> @@ -491,6 +503,17 @@ END; row could be from a view). The fields of the row type inherit the table's field size or precision for data types such as <type>char(n)</type>. +<programlisting> +CREATE FUNCTION use_two_tables(tablename) RETURNS TEXT AS ' +DECLARE + in_t ALIAS FOR $1; + use_t table2name%ROWTYPE; +BEGIN + SELECT * INTO use_t FROM table2name WHERE ... ; + RETURN in_t.f1 || use_t.f3 || in_t.f5 || use_t.f7; +END; +' LANGUAGE 'plpgsql'; +</programlisting> </para> </sect2> |