Re: Trouble with NEW

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Bob Pawley <rjpawley(at)shaw(dot)ca>
Cc: Alan Hodgson <ahodgson(at)simkin(dot)ca>, pgsql-general(at)postgresql(dot)org
Subject: Re: Trouble with NEW
Date: 2012-07-19 17:26:07
Message-ID: 5008432F.9080408@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2012-07-19 18:26:39 Re: Trouble with NEW
Previous Message Luiz Damim 2012-07-19 16:37:16 Default value of serial fields changes after restore