Re: Sequence Incrementing by 2 insted of 1

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Sequence Incrementing by 2 insted of 1
Date: 2009-04-28 11:58:20
Message-ID: gt6r0s$kao$1@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2009-04-28, David <david(at)vanlaatum(dot)id(dot)au> wrote:

> Ok got permission to send the code I think I have got all the relevent bits.

>
>CREATE TABLE currentcall (
> cadc_taskno integer DEFAULT nextval(('currentcall_cadc_taskno_seq'::text)::regclass) NOT NULL,
> coversight character varying(4),
...

>CREATE RULE currentcall_insert AS ON INSERT TO currentcall DO INSERT INTO
> taskchangelog (tasknum, newstatus, newtech, status, newpriority,
> newestcomplete, newclass, newnewtask) VALUES (new.cadc_taskno,
^^^^^^^^^^^^^^^
> new.cstatus, new.ctechalloc, new.ccustcomment, new.cfprior,
> new.cestcomplete, new.cjobclass, (new.cnewtask = 'Y'::bpchar));

if you're inserting DEFAULT into the cadc_taskno column (or not
explicitly setting that column) the re-writer will substitute

nextval(('currentcall_cadc_taskno_seq'::text)::regclass)

And that will be evaluated once for the insert and again for the rule.

this is documented somewhere.... I think

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jasen Betts 2009-04-28 12:21:19 Re: Web + Slicing/Paging datas
Previous Message A. Kretschmer 2009-04-28 11:49:33 Re: Huge sample dataset for testing.