Skip site navigation (1) Skip section navigation (2)

Adding a crucial element to an example

From: John Gage <jsmgage(at)numericable(dot)fr>
To: pgsql-docs(at)postgresql(dot)org
Subject: Adding a crucial element to an example
Date: 2010-07-23 10:02:02
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-docs
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.


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;

SELECT name, double_salary(emp.*) AS dream FROM emp WHERE emp.cubicle  
~= point '(2,1)';

name | dream
  Bill | 8400


pgsql-docs by date

Next:From: Craig JamesDate: 2010-07-23 21:47:23
Subject: Re: Using more tha one index per table
Previous:From: Torsten Z├╝hlsdorffDate: 2010-07-23 09:22:18
Subject: Re: Using more tha one index per table

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group