Re: [GENERAL] Best way to create unique primary keys across schemas?

2012-01-29 Thread Jasen Betts
On 2012-01-23, panam wrote: > Hi, > > If I'd like to have primary keys generated ("numeric" style, no UUIDs) that > are unique across schemas is the best option to allocate a fixed sequence > range (min,max) to the sequences of all schemas? given that challenge the easiest solution is to just cre

Re: [GENERAL] Best way to create unique primary keys across schemas?

2012-01-26 Thread Chris Angelico
On Fri, Jan 27, 2012 at 4:56 AM, panam wrote: > Thanks, yeah, but the dummy tables are needed anyway in my case for those > entities that are shared among the tenants :) Ah! Then that's easy :) ChrisA -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your

Re: [GENERAL] Best way to create unique primary keys across schemas?

2012-01-26 Thread panam
Thanks, yeah, but the dummy tables are needed anyway in my case for those entities that are shared among the tenants :) -- View this message in context: http://postgresql.1045698.n5.nabble.com/Best-way-to-create-unique-primary-keys-across-schemas-tp5165043p5433562.html Sent from the PostgreSQL -

Re: [GENERAL] Best way to create unique primary keys across schemas?

2012-01-26 Thread Chris Angelico
On Thu, Jan 26, 2012 at 2:12 AM, panam wrote: > CREATE TABLE tbl (ID bigint default nextval('global_seq') primary key,foo > varchar,bar varchar);  --in public schema > CREATE TABLE schema1.tbl (LIKE public.tbl INCLUDING ALL);  --draws ids from > sequence in public schema > CREATE TABLE schema2.tbl

Re: [GENERAL] Best way to create unique primary keys across schemas?

2012-01-25 Thread panam
OK, thanks for replys. To sum up, this is what I now consider best practice: CREATE schema schema1; CREATE schema schema2; CREATE SEQUENCE global_seq; --in public schema CREATE TABLE tbl (ID bigint default nextval('global_seq') primary key,foo varchar,bar varchar); --in public schema CREATE TA

Re: [GENERAL] Best way to create unique primary keys across schemas?

2012-01-24 Thread Chris Angelico
On Wed, Jan 25, 2012 at 9:54 AM, panam wrote: > What do you mean with "explicit sequence object"? An own sequence for each > table per schema? This: On Wed, Jan 25, 2012 at 10:23 AM, Merlin Moncure wrote: > Barring domains, you can just manually apply the default instead of > using a serial typ

Re: [GENERAL] Best way to create unique primary keys across schemas?

2012-01-24 Thread Rob Sargent
On 01/24/2012 04:23 PM, Merlin Moncure wrote: > On Tue, Jan 24, 2012 at 5:23 AM, panam wrote: >> Wow, this is pretty useful. Just to fit it more to my original use case, I >> used this: >> >> CREATE schema schema1; >> CREATE schema schema2; >> CREATE TABLE tbl (ID serial primary key,foo varchar,

Re: [GENERAL] Best way to create unique primary keys across schemas?

2012-01-24 Thread Merlin Moncure
On Tue, Jan 24, 2012 at 5:23 AM, panam wrote: > Wow, this is pretty useful. Just to fit it more to my original use case, I > used this: > > CREATE schema schema1; > CREATE schema schema2; > CREATE TABLE tbl (ID serial primary key,foo varchar,bar varchar);  --in > public schema > CREATE TABLE schem

Re: [GENERAL] Best way to create unique primary keys across schemas?

2012-01-24 Thread panam
Chris Angelico wrote > > I would recommend using an explicit sequence object rather than > relying on odd behavior like this; for instance, if you now drop > public.tbl, the sequence will be dropped too. However, what you have > there is going to be pretty close to the same result anyway. > Oops

Re: [GENERAL] Best way to create unique primary keys across schemas?

2012-01-24 Thread Chris Angelico
On Tue, Jan 24, 2012 at 10:23 PM, panam wrote: > Wow, this is pretty useful. Just to fit it more to my original use case, I > used this: > > CREATE TABLE tbl (ID serial primary key,foo varchar,bar varchar);  --in > public schema > CREATE TABLE schema1.tbl (LIKE public.tbl INCLUDING ALL);  --draws

Re: [GENERAL] Best way to create unique primary keys across schemas?

2012-01-24 Thread panam
Chris Angelico wrote > > > You can "share" a sequence object between several tables. This can > happen somewhat unexpectedly, as I found out to my surprise a while > ago: > > CREATE TABLE tbl1 (ID serial primary key,foo varchar,bar varchar); > INSERT INTO tbl1 (foo,bar) VALUES ('asdf','qwer');

Re: [GENERAL] Best way to create unique primary keys across schemas?

2012-01-23 Thread Chris Angelico
On Mon, Jan 23, 2012 at 11:19 AM, panam wrote: > Hi, > > If I'd like to have primary keys generated ("numeric" style, no UUIDs) that > are unique across schemas is the best option to allocate a fixed sequence > range (min,max) to the sequences of all schemas? You can "share" a sequence object bet

Re: [GENERAL] Best way to create unique primary keys across schemas?

2012-01-22 Thread Scott Marlowe
On Sun, Jan 22, 2012 at 5:19 PM, panam wrote: > Hi, > > If I'd like to have primary keys generated ("numeric" style, no UUIDs) that > are unique across schemas is the best option to allocate a fixed sequence > range (min,max) to the sequences of all schemas? That's how I do it. If you use a bigs

[GENERAL] Best way to create unique primary keys across schemas?

2012-01-22 Thread panam
Hi, If I'd like to have primary keys generated ("numeric" style, no UUIDs) that are unique across schemas is the best option to allocate a fixed sequence range (min,max) to the sequences of all schemas? Thanks panam -- View this message in context: http://postgresql.1045698.n5.nabble.com/Best-w