numerus/verify/invoice_number_counter.sql
jordi fita mas 880c4f53b2 Add the function to get the next invoice number
I can not use a PostgreSQL sequence because invoices need to be gapless,
and sequences are designed to not rollback, for performance reasons.  In
this case, the performance is secondary because the law does not care.
2023-02-17 14:48:24 +01:00

15 lines
398 B
PL/PgSQL

-- Verify numerus:invoice_number_counter on pg
begin;
select company_id
, year
, currval
from numerus.invoice_number_counter
where false;
select 1 / count(*) from pg_class where oid = 'numerus.invoice_number_counter'::regclass and relrowsecurity;
select 1 / count(*) from pg_policy where polname = 'company_policy' and polrelid = 'numerus.invoice_number_counter'::regclass;
rollback;