Add new field with auto-icrement to existing table

From: Brice André <brice(at)famille-andre(dot)be>
To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Add new field with auto-icrement to existing table
Date: 2015-01-06 16:31:49
Message-ID: CAOBG12nkWeiZwZFR+yG2bYjWC+HWnBoNidVHLEiY67KTek6W1g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Dear all,

I have a database structure with several default empty tables defines in an
admin schema. For example :

CREATE TABLE admin."ConfigurableWindowGUIEntryInternal"
(
"DbSyncID" bigint NOT NULL,
"DbSyncInsertedBackupVersion" bigint NOT NULL,
...
)
WITH (
OIDS=FALSE
);

And, for each client, I have a dedicated schema with tables that derive
from those admin tables, and use the two first elements as primary keys
(DbSyncID and DbSyncInsertedBackupVersion). For example :

CREATE TABLE user_1."ConfigurableWindowGUIEntryInternal"
(
CONSTRAINT "ConfigurableWindowGUIEntry_pk" PRIMARY KEY ("DbSyncID",
"DbSyncInsertedBackupVersion")
)
INHERITS (admin."ConfigurableWindowGUIEntryInternal")
WITH (
OIDS=FALSE
);

This schema is used for synchronisation of the database between the server
and client applications and I do not want to change anything in this
communication protocol.

But now, I would want to develop a server-based application. And this
application would need a single column unique ID for referencing tables
entries. My current primary key does not fit my needs as it is based on two
columns. So, I would want to add a new field on all derived tables. And, as
I don't want to change the synchronisation stuff, the values of this new
field should be assigned automatically.

Is there a way to add this once for all by changing the parent table or do
I need to add the field for each derived table ? And how can I perform
this, taking into account that the tables already contain data ?

Thanks in advance for your help.

Regards,
Brice

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Kretschmer 2015-01-06 17:44:37 Re: Add new field with auto-icrement to existing table
Previous Message Jonathan S. Katz 2014-12-29 16:39:54 Re: localtime(0)