pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ahti Legonkov <lego@127.0.0.1>
Cc: pgsql-sql@postgresql.org
Subject: Re: rules / triggers on insert. why after?
Date: Fri, 12 Jul 2002 11:07:29 -0400
Message-ID: <9792.1026486449@sss.pgh.pa.us> (raw)
In-Reply-To: <3D2EA031.3000104@127.0.0.1>
References: <3D2EA031.3000104@127.0.0.1>

Ahti Legonkov <lego@127.0.0.1> writes:
> CREATE TABLE reo (
>    "REO_ID" int4 DEFAULT nextval('"REO_ID_seq"'::text) NOT NULL,
>    "TYPE" varchar(64) NOT NULL,
>    CONSTRAINT "REO_ID_reo_ukey" UNIQUE ("REO_ID"),
>    CONSTRAINT reo_pkey PRIMARY KEY ("REO_ID")
> );

> CREATE TABLE lreo (
>    "CITY" varchar(64),
>    "STREET" varchar(64),
>    "PRICE" int4,
>    "REO_ID" int4 DEFAULT currval('"REO_ID_seq"'::text),
>    CONSTRAINT "REO_ID_land_reo_ukey" UNIQUE ("REO_ID"),
>    CONSTRAINT "fk_LREO_REO_ID" FOREIGN KEY ("REO_ID") REFERENCES reo 
> ("REO_ID") ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE 
> INITIALLY IMMEDIATE
> );

That default for reo_id is too fragile to consider using in any case.
You are making way too many assumptions about when defaults will be
evaluated relative to other actions (such as rule/trigger firings).

I'd suggest that you have no default for column reo_id, and instead
have a BEFORE INSERT trigger for lreo that (a) inserts a row into reo
and (b) sets new.reo_id to the inserted key (which you could get from
currval at that point).

			regards, tom lane



view thread (3+ messages)

Message-ID: <9792.1026486449@sss.pgh.pa.us>
Permalink:  ../9792.1026486449@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/9792.1026486449@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, lego@127.0.0.1
  Subject: Re: rules / triggers on insert. why after?
  In-Reply-To: <9792.1026486449@sss.pgh.pa.us>

* 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