Skip site navigation (1) Skip section navigation (2)

Re: Updatable view and default sequence values

From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Kouber Saparev <postgres(at)saparev(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Updatable view and default sequence values
Date: 2006-05-22 16:50:27
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-admin
On Tue, May 16, 2006 at 04:16:55PM +0300, Kouber Saparev wrote:
> The tricky part comes when I try to make my view insertable. Normally 
> I'd insert without specifying the sequence values, but in some cases I'd 
> want also to have full control of what's going into the underlying 
> tables. The thing is that when I try to do it the simple way by 
> specifying default values in the view itself:
> ALTER TABLE s_purchase ALTER COLUMN purchase_sid SET DEFAULT 
> NEXTVAL('purchase_purchase_sid_seq');
> ALTER TABLE s_purchase ALTER COLUMN subscription_purchase_sid SET 
> DEFAULT NEXTVAL('subscription_purchase_subscription_purchase_sid_seq');
You're doing ALTER TABLE on a view?

> CREATE RULE s_purchase_insert AS
>   ON INSERT TO s_purchase DO INSTEAD (
>     INSERT INTO purchase
>       (purchase_sid, data)
>     VALUES
>       (NEW.purchase_sid, NEW.pdata);
>     INSERT INTO subscription_purchase
>       (subscription_purchase_sid, purchase_sid, data)
>     VALUES
>       (NEW.subscription_purchase_sid, NEW.purchase_sid, NEW.sdata);
> );

Why not just use CURRVAL('purchase_purchase_sid_seq') in the rule?
Jim C. Nasby, Sr. Engineering Consultant      jnasby(at)pervasive(dot)com
Pervasive Software    work: 512-231-6117
vcard:       cell: 512-569-9461

In response to


pgsql-admin by date

Next:From: Andy ShellamDate: 2006-05-22 17:56:45
Subject: Re: Error in Access
Previous:From: Jim C. NasbyDate: 2006-05-22 16:45:44
Subject: Re: Synchronize Backup to another remote database

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group