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

From: rob stone <floriparob(at)gmail(dot)com>
To: Michelle Konzack <linux4michelle(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: COL unique (CustomerID) plus COL unique (COUNT) inside CustomerID
Date: 2016-09-01 13:35:17
Message-ID: 1472736917.4016.2.camel@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Thu, 2016-09-01 at 12:28 +0300, Michelle Konzack wrote:
> Hello to all,
>
> after a period of silence from Debian, Courier, PHP and PostgreSQL
> I  am
> half back and running into a problem...  :-/
>
> 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.
>
> 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?
>
> Thanks in avance
>
> -- 
> Michelle Konzack        ITSystems
> GNU/Linux Developer     0033-6-61925193
>
>

Hi,

(I wouldn't name a column "count").

SELECT MAX(count_er) FROM my_customer_table WHERE cust_id = $1;

Add one to the result. Do INSERT.

As SELECT MAX is a GROUP function it will return zero if the cust_id
doesn't exist.

HTH,

Rob

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Kretschmer 2016-09-01 14:01:22 Re: COL unique (CustomerID) plus COL unique (COUNT) inside CustomerID
Previous Message Igor Neyman 2016-09-01 13:08:24 Re: Clustered index to preserve data locality in a multitenant application?