agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
Add new field with auto-icrement to existing table
3+ messages / 2 participants
[nested] [flat]

* Add new field with auto-icrement to existing table
@ 2015-01-06 16:31  Brice André <brice@famille-andre.be>
  0 siblings, 1 reply; 3+ messages in thread

From: Brice André @ 2015-01-06 16:31 UTC (permalink / raw)
  To: 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

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Add new field with auto-icrement to existing table
@ 2015-01-06 17:44  Andreas Kretschmer <akretschmer@spamfence.net>
  parent: Brice André <brice@famille-andre.be>
  0 siblings, 1 reply; 3+ messages in thread

From: Andreas Kretschmer @ 2015-01-06 17:44 UTC (permalink / raw)
  To: pgsql-sql

Brice André <brice@famille-andre.be> wrote:

> 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.

Create a new Sequence. I think, that should fit your requirement.

Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Add new field with auto-icrement to existing table
@ 2015-01-06 20:26  Brice André <brice@famille-andre.be>
  parent: Andreas Kretschmer <akretschmer@spamfence.net>
  0 siblings, 0 replies; 3+ messages in thread

From: Brice André @ 2015-01-06 20:26 UTC (permalink / raw)
  To: Andreas Kretschmer <akretschmer@spamfence.net>; +Cc: pgsql-sql

Exactly what I needed.

Thanks,
Brice

2015-01-06 18:44 GMT+01:00 Andreas Kretschmer <akretschmer@spamfence.net>:

> Brice André <brice@famille-andre.be> wrote:
>
> > 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.
>
> Create a new Sequence. I think, that should fit your requirement.
>
> Andreas
> --
> Really, I'm not out to destroy Microsoft. That will just be a completely
> unintentional side effect.                              (Linus Torvalds)
> "If I was god, I would recompile penguin with --enable-fly."   (unknown)
> Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2015-01-06 20:26 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-01-06 16:31 Add new field with auto-icrement to existing table Brice André <brice@famille-andre.be>
2015-01-06 17:44 ` Andreas Kretschmer <akretschmer@spamfence.net>
2015-01-06 20:26   ` Brice André <brice@famille-andre.be>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox