On 26/02/2020 10:27, Vik Fearing wrote:
> WITH
> u (invoice_number) AS (
> UPDATE invoice_numbers
> SET invoice_number = invoice_number + 1
> WHERE country = $1
> RETURNING invoice_number
> ),
> i (invoice_number) AS (
> INSERT INTO invoice_numbers (country, invoice_number)
>
This looks to be the way to go! Thank you very much. I'll do the function
in my application code to have it in version control. But it helped me wrap
my head around it.
Den ons. 26. feb. 2020 kl. 10.27 skrev Vik Fearing :
> On 26/02/2020 09:38, Søren Frisk wrote:
> > Hi all
> >
> > I'm trying to
On 2020-02-26 09:38:57 +0100, Søren Frisk wrote:
> I'm trying to find a way to increment an invoice number. And i think it would
> be pretty straight forward just using a SERIAL int.
Be careful: Sequences may have gaps (e.g. because of rolled back
transactions, but maybe also for other reasons). I
On 26/02/2020 09:38, Søren Frisk wrote:
> Hi all
>
> I'm trying to find a way to increment an invoice number. And i think it
> would be pretty straight forward just using a SERIAL int. But as we're
> selling across multiple countries, i need the invoice increment to be reset
> by a country_id. any
On Wed, 26 Feb 2020 at 09:54, Søren Frisk wrote:
> Hi all
>
> I'm trying to find a way to increment an invoice number. And i think it
> would be pretty straight forward just using a SERIAL int. But as we're
> selling across multiple countries, i need the invoice increment to be reset
> by a count