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

Commit ffce35f

Browse files
committed
Add a tip showing how functions on composite types can be used to
emulate computed fields. I suppose this is why the Berkeley boys made it work that way in the first place, but the docs never said so anyplace.
1 parent 4e64e7f commit ffce35f

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

doc/src/sgml/xfunc.sgml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.93 2005/01/07 22:40:46 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.94 2005/01/07 23:08:44 tgl Exp $
33
-->
44

55
<sect1 id="xfunc">
@@ -450,6 +450,31 @@ SELECT name(emp) AS youngster FROM emp WHERE age(emp) &lt; 30;
450450
</screen>
451451
</para>
452452

453+
<tip>
454+
<para>
455+
The equivalence between functional notation and attribute notation
456+
makes it possible to use functions on composite types to emulate
457+
<quote>computed fields</>.
458+
<indexterm>
459+
<primary>computed field</primary>
460+
</indexterm>
461+
<indexterm>
462+
<primary>field</primary>
463+
<secondary>computed</secondary>
464+
</indexterm>
465+
For example, using the previous definition
466+
for <literal>double_salary(emp)</>, we can write
467+
468+
<screen>
469+
SELECT emp.name, emp.double_salary FROM emp;
470+
</screen>
471+
472+
An application using this wouldn't need to be directly aware that
473+
<literal>double_salary</> isn't a real column of the table.
474+
(You can also emulate computed fields with views.)
475+
</para>
476+
</tip>
477+
453478
<para>
454479
Another way to use a function returning a row result is to pass the
455480
result to another function that accepts the correct row type as input:

0 commit comments

Comments
 (0)