Re: COL unique (CustomerID) plus COL unique (COUNT) inside CustomerID

From: Kevin Grittner <kgrittn(at)gmail(dot)com>
To: Michelle Konzack <linux4michelle(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: COL unique (CustomerID) plus COL unique (COUNT) inside CustomerID
Date: 2016-09-01 18:39:33
Message-ID: CACjxUsOgn9nvfiCbm3BtyVTV4rEYbUkpU9pbw0o2=teXhGvt+w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Sep 1, 2016 at 4:28 AM, Michelle Konzack
<linux4michelle(at)gmail(dot)com> wrote:

> I need a table with an UNIQUE CustomerID which is working fine...
>
> ...BUT I need also a second column with a count, which must be UNIQUE
> inside the CustomerID.

Just to be clear, you probably have a customer table with "CustIomerId"
as its key and are talking about a "child"of that where you want a
2-column key?

> In clear this:
>
> CustID Count
> 1 1
> 1 2
> 1 3
>
> 2 1
> 2 2
>
> 3 1
> 3 2
> 3 3
> ...
>
> How to do this?

If, for example, the child table is a list of customer contacts,
you might add a "LastContactNo" column to the customer table,
defaulting to zero on customer insert, and which you increment to
get values for the second key column in the contact table.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jennyfer Sanchez 2016-09-01 20:22:16 error initializing the db
Previous Message Mike Sofen 2016-09-01 17:44:32 Re: Rackspace to RDS using DMS (Postgres 9.2)