Re: Trouble with NEW - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Trouble with NEW
Date
Msg-id 5008432F.9080408@gmail.com
Whole thread Raw
In response to Re: Trouble with NEW  ("Bob Pawley" <rjpawley@shaw.ca>)
Responses Re: Trouble with NEW  ("David Johnston" <polobo@yahoo.com>)
List pgsql-general
On 07/19/2012 08:41 AM, Bob Pawley wrote:
> In all my reading of new and old I never made that connection.

It makes more sense if you know what NEW and OLD represent.

What follows is a simplification:
1)Postgres uses Multiversion Concurrency Control(MVCC). See here for
brief intro:
http://www.postgresql.org/docs/9.0/interactive/mvcc-intro.html

2) As a result on:
A) INSERT. For each record you have only a corresponding NEW record
that holds the values you are inserting.
b) UPDATE. In Postgres an update is a two part process where you delete
the old record and insert the new record. In that case you have both an
OLD and a NEW record representing the respective values.
c) DELETE. You are getting rid of a record and all you have is the OLD
record representing the record you are deleting.

3) When you use a trigger or rule that uses the OLD, NEW records it only
has access to those records for the table it is attached to.

4) If you want to pull information from another table, you either need
to set up a FOREIGN KEY relationship that you can leverage or you need
to do a query in the trigger function that pulls in the necessary
information.

>
> Thanks Adrian
>
> Bob

>


--
Adrian Klaver
adrian.klaver@gmail.com



pgsql-general by date:

Previous
From: Younus
Date:
Subject: Re: How to stop a query
Next
From: Luiz Damim
Date:
Subject: Default value of serial fields changes after restore