Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id C112463234B for ; Fri, 23 Jul 2010 07:02:13 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 12841-01 for ; Fri, 23 Jul 2010 10:02:04 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp2.tech.numericable.fr (smtp2.tech.numericable.fr [82.216.111.38]) by mail.postgresql.org (Postfix) with ESMTP id 95B26634A86 for ; Fri, 23 Jul 2010 07:02:05 -0300 (ADT) Received: from [10.0.1.2] (abo-102-217-68.trs.modulonet.fr [85.68.217.102]) by smtp2.tech.numericable.fr (Postfix) with ESMTP id A4F4A18D805 for ; Fri, 23 Jul 2010 12:02:02 +0200 (CEST) Message-Id: <9A88E54D-2CF7-403F-A0D8-35B9ECDC7103@numericable.fr> From: John Gage To: pgsql-docs@postgresql.org Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v936) Subject: Adding a crucial element to an example Date: Fri, 23 Jul 2010 12:02:02 +0200 X-Mailer: Apple Mail (2.936) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.79 tagged_above=-5 required=5 tests=BAYES_50=0.8, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/147 X-Sequence-Number: 5803 The examples in the documentation are the most valuable part. In this section, you create the table for the example, but you do not populate it, although the example select statements are against the phantom population that has not been inserted. I suggest strongly including the minimal code necessary to populate the table, so that the user doesn't have to populate it himself. Call me lazy, but I did go into pgAdmin and insert values after creating a primary key. Cutting and pasting examples and then playing around with them is by far, by far the most productive way to learn the system. John 35.4.2. SQL Functions on Composite Types When writing functions with arguments of composite types, we must not only specify which argument we want (as we did above with $1 and $2) but also the desired attribute (field) of that argument. For example, suppose that emp is a table containing employee data, and therefore also the name of the composite type of each row of the table. Here is a function double_salary that computes what someone's salary would be if it were doubled: CREATE TABLE emp ( name text, salary numeric, age integer, cubicle point ); CREATE FUNCTION double_salary(emp) RETURNS numeric AS $$ SELECT $1.salary * 2 AS salary; $$ LANGUAGE SQL; SELECT name, double_salary(emp.*) AS dream FROM emp WHERE emp.cubicle ~= point '(2,1)'; name | dream ------+------- Bill | 8400