Adding a crucial element to an example

Поиск
Список
Период
Сортировка
От John Gage
Тема Adding a crucial element to an example
Дата
Msg-id 9A88E54D-2CF7-403F-A0D8-35B9ECDC7103@numericable.fr
обсуждение исходный текст
Ответы Re: Adding a crucial element to an example  (Peter Eisentraut <peter_e@gmx.net>)
Список 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.

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

В списке pgsql-docs по дате отправления:

Предыдущее
От: Thom Brown
Дата:
Сообщение: Tidy up boolean data type page
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: Tidy up boolean data type page