Re: [GENERAL] unique across two tables

2011-06-26 Thread Gavin Flower
On 23/06/11 23:28, Tarlika Elisabeth Schmitz wrote: Hello Gavin, On Wed, 22 Jun 2011 20:53:19 +1200 Gavin Flower wrote: [...] This design ensures that: names of towns are unique within a given country and>region. Note you will still need business logic, in a trigger or some such, to ensure

Re: [GENERAL] unique across two tables

2011-06-23 Thread Edoardo Panfili
On 23/06/11 22.39, Tomas Vondra wrote: Dne 23.6.2011 20:39, Edoardo Panfili napsal(a): I Have the same problem: one ID must be unique. Three tables inherits from the same parent table the id column, the ID is is defined as: id bigint DEFAULT nextval('sequence_name') in the parent table. Can I a

Re: [GENERAL] unique across two tables

2011-06-23 Thread David Johnston
> On 22/06/11 18.30, David Johnston wrote: > > The only (obvious to me) way to really solve the problem - invisibly - > > is to allow for table-less unique indexes that multiple tables can > > share and that have a pointer to the "source" table for any particular entry > in the index. > > The other

Re: [GENERAL] unique across two tables

2011-06-23 Thread Tomas Vondra
Dne 23.6.2011 20:39, Edoardo Panfili napsal(a): > I Have the same problem: one ID must be unique. > Three tables inherits from the same parent table the id column, the ID > is is defined as: > id bigint DEFAULT nextval('sequence_name') > in the parent table. > > Can I assume that a sequence ensure

Re: [GENERAL] unique across two tables

2011-06-23 Thread Edoardo Panfili
On 22/06/11 18.30, David Johnston wrote: The only (obvious to me) way to really solve the problem - invisibly - is to allow for table-less unique indexes that multiple tables can share and that have a pointer to the "source" table for any particular entry in the index. The other method being disc

Re: [GENERAL] unique across two tables

2011-06-23 Thread Tarlika Elisabeth Schmitz
Hello Gavin, On Wed, 22 Jun 2011 20:53:19 +1200 Gavin Flower wrote: > [...] >This design ensures that: names of towns are unique within a given >country and >region. >Note you will still need business logic, in a trigger or some such, to >ensure that only one town within a given country and

Re: [GENERAL] unique across two tables

2011-06-22 Thread Merlin Moncure
On Wed, Jun 22, 2011 at 11:30 AM, David Johnston wrote: >> yeah -- postgresql table inheritance [...] underpins the table inheritance > feature [...] > > Thank you Master of the Obvious  ;) > > I do think you meant to say it underpins the "Table Partitioning Feature" > which, through the use of IN

Re: [GENERAL] unique across two tables

2011-06-22 Thread David Johnston
> yeah -- postgresql table inheritance [...] underpins the table inheritance feature [...] Thank you Master of the Obvious ;) I do think you meant to say it underpins the "Table Partitioning Feature" which, through the use of INSERT triggers to at least propagate the inserts to the proper tables

Re: [GENERAL] unique across two tables

2011-06-22 Thread Merlin Moncure
On Wed, Jun 22, 2011 at 8:34 AM, David Johnston wrote: > Your statement is utterly false simply by virtue of the documentation. > > > > Inserts never propagate to other tables in a hierarchy > > Indexes/Constraints only apply to individual tables > > > > Since inserts do not propagate the base tab

Re: [GENERAL] unique across two tables

2011-06-22 Thread Misa Simic
general-ow...@postgresql.org [mailto: > pgsql-general-ow...@postgresql.org] *On Behalf Of *Misa Simic > *Sent:* Wednesday, June 22, 2011 8:49 AM > *To:* Tarlika Elisabeth Schmitz > *Cc:* pgsql-general@postgresql.org > *Subject:* Re: [GENERAL] unique across two tables > > ** ** &g

Re: [GENERAL] unique across two tables

2011-06-22 Thread David Johnston
-ow...@postgresql.org] On Behalf Of Misa Simic Sent: Wednesday, June 22, 2011 8:49 AM To: Tarlika Elisabeth Schmitz Cc: pgsql-general@postgresql.org Subject: Re: [GENERAL] unique across two tables Hi Tarlika, I think easy solution could be: create baseTable with just one column as PK

Re: [GENERAL] unique across two tables

2011-06-22 Thread Misa Simic
Hi Tarlika, I think easy solution could be: create baseTable with just one column as PK TableA inhertis baseTable, it will have inherited Column + additianl tables for TableA TableB inherits baseTable, it will aslo have inherited Column + additianl tables for TableB Insert in any table TableA o

Re: [GENERAL] unique across two tables

2011-06-22 Thread Gavin Flower
Hi Tarlika, I hope this approach is of interest. This is how I would design a database to solve the problem - unfortunately, this may not be appropriate for your particular situation. This design ensures that: names of towns are unique within a given country and region. plus it can support

Re: [GENERAL] unique across two tables

2011-06-20 Thread Tarlika Elisabeth Schmitz
On Mon, 20 Jun 2011 19:42:20 +0200 Alban Hertroys wrote: >On 20 Jun 2011, at 17:03, Tarlika Elisabeth Schmitz wrote: > >> I have two tables, town and townalias, the latter containing >> alternative town names. >> I would like to ensure that a town name is unique per >> country-region across the t

Re: [GENERAL] unique across two tables

2011-06-20 Thread Alban Hertroys
On 20 Jun 2011, at 17:03, Tarlika Elisabeth Schmitz wrote: > I have two tables, town and townalias, the latter containing alternative > town names. > I would like to ensure that a town name is unique per > country-region across the two tables. > > Can I do this with a constraint ot do I need to i

Re: [GENERAL] unique across two tables

2011-06-20 Thread tv
> I have two tables, town and townalias, the latter containing alternative > town names. > I would like to ensure that a town name is unique per > country-region across the two tables. > > Can I do this with a constraint ot do I need to implement the logic via > trigger? You can't have a constrain

[GENERAL] unique across two tables

2011-06-20 Thread Tarlika Elisabeth Schmitz
I have two tables, town and townalias, the latter containing alternative town names. I would like to ensure that a town name is unique per country-region across the two tables. Can I do this with a constraint ot do I need to implement the logic via trigger? = PostgreSQl 8.4 CREATE TABL