pg.ddx.io pgsql-docs@postgresql.org mailing list archive
help / color / mirror / Atom feedAdding a crucial element to an example
5+ messages / 3 participants
[nested] [flat]
* Adding a crucial element to an example
@ 2010-07-23 10:02 John Gage <jsmgage@numericable.fr>
0 siblings, 1 reply; 5+ messages in thread
From: John Gage @ 2010-07-23 10:02 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Adding a crucial element to an example
@ 2010-07-24 12:21 Peter Eisentraut <peter_e@gmx.net>
parent: John Gage <jsmgage@numericable.fr>
0 siblings, 1 reply; 5+ messages in thread
From: Peter Eisentraut @ 2010-07-24 12:21 UTC (permalink / raw)
To: John Gage <jsmgage@numericable.fr>; +Cc: pgsql-docs
On fre, 2010-07-23 at 12:02 +0200, John Gage wrote:
> 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.
Could you send a patch, or a list of the statements that need to be
inserted?
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Adding a crucial element to an example
@ 2010-07-24 14:26 John Gage <jsmgage@numericable.fr>
parent: Peter Eisentraut <peter_e@gmx.net>
0 siblings, 2 replies; 5+ messages in thread
From: John Gage @ 2010-07-24 14:26 UTC (permalink / raw)
To: Peter Eisentraut <peter_e@gmx.net>; +Cc: pgsql-docs
After the CREATE statement I would simply put:
INSERT INTO emp VALUES ('Bill', 4200, 45, '(2,1)');
What that accomplishes is making it so the user can simply copy and
paste the entire section and run it in pg_admin. Then, the user can
start fiddling with it as he wants to.
I know this sounds terribly simple, but simplicity is good,
particularly when you're climbing a steep learning curve. And there
is certainly, unequivocally, no harm in simplicity.
Thanks,
John
On Jul 24, 2010, at 2:21 PM, Peter Eisentraut wrote:
> On fre, 2010-07-23 at 12:02 +0200, John Gage wrote:
>> 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.
>
> Could you send a patch, or a list of the statements that need to be
> inserted?
>
>
> --
> Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-docs
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Adding a crucial element to an example
@ 2010-07-25 08:31 Peter Eisentraut <peter_e@gmx.net>
parent: John Gage <jsmgage@numericable.fr>
1 sibling, 0 replies; 5+ messages in thread
From: Peter Eisentraut @ 2010-07-25 08:31 UTC (permalink / raw)
To: John Gage <jsmgage@numericable.fr>; +Cc: pgsql-docs
On lör, 2010-07-24 at 16:26 +0200, John Gage wrote:
> After the CREATE statement I would simply put:
>
> INSERT INTO emp VALUES ('Bill', 4200, 45, '(2,1)');
done
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Adding a crucial element to an example
@ 2010-08-11 21:22 Bruce Momjian <bruce@momjian.us>
parent: John Gage <jsmgage@numericable.fr>
1 sibling, 0 replies; 5+ messages in thread
From: Bruce Momjian @ 2010-08-11 21:22 UTC (permalink / raw)
To: John Gage <jsmgage@numericable.fr>; +Cc: Peter Eisentraut <peter_e@gmx.net>; pgsql-docs
John Gage wrote:
> After the CREATE statement I would simply put:
>
> INSERT INTO emp VALUES ('Bill', 4200, 45, '(2,1)');
>
> What that accomplishes is making it so the user can simply copy and
> paste the entire section and run it in pg_admin. Then, the user can
> start fiddling with it as he wants to.
>
> I know this sounds terribly simple, but simplicity is good,
> particularly when you're climbing a steep learning curve. And there
> is certainly, unequivocally, no harm in simplicity.
Our documentation got this good only through many small improvements
like this. :-)
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2010-08-11 21:22 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-07-23 10:02 Adding a crucial element to an example John Gage <jsmgage@numericable.fr>
2010-07-24 12:21 ` Peter Eisentraut <peter_e@gmx.net>
2010-07-24 14:26 ` John Gage <jsmgage@numericable.fr>
2010-07-25 08:31 ` Peter Eisentraut <peter_e@gmx.net>
2010-08-11 21:22 ` Bruce Momjian <bruce@momjian.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox