From: Matthias Apitz <guru@unixarea.de>
To: Sándor Daku <daku.sandor@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: PostgreSQL server does not increment a SERIAL internally
Date: Mon, 6 Jul 2020 14:27:23 +0200
Message-ID: <20200706122723.GB318@sh4-5.1blu.de> (raw)
In-Reply-To: <CAKyoTgbOW=fr+9x-LCuV6Qthpx=uSVKYhGX7mif3x6r6zSTKOQ@mail.gmail.com>
References: <20200706094336.GA318@sh4-5.1blu.de>
<CAKyoTgbOW=fr+9x-LCuV6Qthpx=uSVKYhGX7mif3x6r6zSTKOQ@mail.gmail.com>
El día Montag, Juli 06, 2020 a las 01:58:04 +0200, Sándor Daku escribió:
> > We update the serial 'acq_haushalt_hnr_seq' with this statement after
> > loading:
> >
>
> What does "loading" mean, and why do you reset the sequence after loading?
> (And as I can see you setting it to the value it most likely already has.)
> My guess is that your problem lurks somewhere here as in certain
> circumstances you reset it to an incorrect(previous) value.
Hello Sándor,
All the tables (~400) are loaded from an export in CSV like format done
from the same Sybase ASE database with this commands for any table:
08:08:00 TRUNCATE TABLE acq_haushalt ;
08:08:00 TRUNCATE TABLE
08:08:01 \COPY acq_haushalt FROM '/home/sisis/guru/sisisDBsrap14/CC-acq_haushalt.load' WITH ( NULL '' , DELIMITER '|' )
08:08:01 COPY 2862
and afterwards we have to adjust the serials to the highest used value
with the shown command:
>
>
> > /* table: acq_haushalt */
> > DO $$
> > DECLARE
> > max_id int;
> > BEGIN
> > if to_regclass('acq_haushalt') is not null then
> > SELECT INTO max_id GREATEST(COALESCE(max(hnr), 0),0) + 1 FROM
> > acq_haushalt;
> > RAISE NOTICE '% % %', 'acq_haushalt', 'hnr', max_id ;
> > EXECUTE 'ALTER SEQUENCE acq_haushalt_hnr_seq RESTART ' || max_id::text;
> > end if;
> > END $$ LANGUAGE plpgsql;
It's output (for this table) was:
NOTICE: acq_haushalt hnr 3183
which is correct because it matches the highest value +1 of 'acq_haushalt.hnr'.
matthias
--
Matthias Apitz, ✉ guru@unixarea.de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub
May, 9: Спаси́бо освободители! Thank you very much, Russian liberators!
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: guru@unixarea.de, daku.sandor@gmail.com
Subject: Re: PostgreSQL server does not increment a SERIAL internally
In-Reply-To: <20200706122723.GB318@sh4-5.1blu.de>
References: <20200706094336.GA318@sh4-5.1blu.de> <CAKyoTgbOW=fr+9x-LCuV6Qthpx=uSVKYhGX7mif3x6r6zSTKOQ@mail.gmail.com> <20200706122723.GB318@sh4-5.1blu.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox