Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jsQDb-0004XQ-KV for pgsql-general@arkaria.postgresql.org; Mon, 06 Jul 2020 12:27:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jsQDa-00062Q-Ek for pgsql-general@arkaria.postgresql.org; Mon, 06 Jul 2020 12:27:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jsQDa-00062J-6c for pgsql-general@lists.postgresql.org; Mon, 06 Jul 2020 12:27:30 +0000 Received: from sh4-5.1blu.de ([178.254.11.41]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jsQDX-0005Ym-Gm for pgsql-general@lists.postgresql.org; Mon, 06 Jul 2020 12:27:29 +0000 Received: from ftp51246-2575596 by sh4-5.1blu.de with local (Exim 4.90_1) (envelope-from ) id 1jsQDT-0002gT-1i; Mon, 06 Jul 2020 14:27:23 +0200 Date: Mon, 6 Jul 2020 14:27:23 +0200 From: Matthias Apitz To: =?utf-8?Q?S=C3=A1ndor?= Daku Cc: pgsql-general@lists.postgresql.org Subject: Re: PostgreSQL server does not increment a SERIAL internally Message-ID: <20200706122723.GB318@sh4-5.1blu.de> Reply-To: Matthias Apitz References: <20200706094336.GA318@sh4-5.1blu.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Operating-System: FreeBSD 12.0-CURRENT r314251 (amd64) X-message-flag: Mails containing HTML will not be read! Please send only plain text. User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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!