pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: silly_sad <sad@bankir.ru>
Cc: pgsql-sql@postgresql.org
Subject: Re: currval() within one statement
Date: Tue, 22 Jan 2008 12:18:47 +0000
Message-ID: <4795DF27.5030602@archonet.com> (raw)
In-Reply-To: <4795D321.5050409@bankir.ru>
References: <4795984E.7030904@bankir.ru>
	<20080122073637.GB21676@a-kretschmer.de>
	<4795A152.3080400@bankir.ru>
	<4795B3D4.5020201@archonet.com>
	<4795C3E8.9080607@bankir.ru>
	<4795C7E8.6030903@archonet.com>
	<4795D321.5050409@bankir.ru>

silly_sad wrote:
> 
> id default value is always set by the trigger before insert on each 
> table for each row.
> 
> The particular subproblem is to
> insert one record into ttt1
> and then insert corresponding record into ttt,
> ___This is the place to use currval.

I'd be tempted to turn it the other way around and have an AFTER trigger 
that just uses NEW.id as the value to put into "ttt".

The reason to use an AFTER trigger is that you know the value can't be 
changed at that point, whereas with a BEFORE trigger it might. In your 
case it doesn't matter, but it's probably a good idea to be consistent 
in these things.

-- 
   Richard Huxton
   Archonet Ltd



view thread (11+ messages)

Message-ID: <4795DF27.5030602@archonet.com>
Permalink:  ../4795DF27.5030602@archonet.com/
Also on:    postgresql.org/message-id/4795DF27.5030602@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, sad@bankir.ru
  Subject: Re: currval() within one statement
  In-Reply-To: <4795DF27.5030602@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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