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

default values in inheritance hierarchies

From: Miroslav Šimulčík <simulcik(dot)miro(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: default values in inheritance hierarchies
Date: 2012-02-27 21:41:59
Message-ID: CAHRNM69yozHY0vZSUnFWdvEihiUrGdenO8wDFSUw_HirsvHHJA@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Hi,

I have two tables defined for example like this:

    create table a1 (id serial primary key, data text);
    create table a2 (id serial primary key, data2 integer) inherits (a1);

The point is, that I want to have two tables with inheritance relation
between them, but each with its own id column (overriden in child table).

Then I execute this sequence of commands:

    insert into a1(data) values('abc');
    insert into a2(data2, data) values(123, 'def');
    update a1 set id = default, data = 'ghi';

I need new IDs on each update, because I store old rows in another table to
keep history of changes. Problem is that update uses values from sequence
belonging to table a1 when updating rows in table a2.

So the content of tables after operations is:

select * from only a1;
 id | data
----+------
  2 | ghi

select * from a2;
 id | data | data2
----+------+-------
  3 | ghi  |   123

The following sequence of commands ends up wit

Responses

pgsql-hackers by date

Next:From: Miroslav ŠimulčíkDate: 2012-02-27 21:50:03
Subject: Re: default values in inheritance hierarchies
Previous:From: Greg SmithDate: 2012-02-27 21:41:43
Subject: Re: pgstat documentation tables

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