0

I wanted to backup my db with no data, but my PK is autoincrementing in no order. On some tables it goes 1,3,5,6,7.., some columns it is 1,3,4.. and some columns even start from 2.

Here is my sql code example:

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

CREATE SCHEMA "Codes";

ALTER SCHEMA "Codes" OWNER TO postgres;

CREATE TABLE "Codes"."VehicleColor" (
"ID" integer NOT NULL,
"Name" character varying(255) NOT NULL,
"Code" character varying(30),
"Note" character varying(2000),
"Active" boolean NOT NULL
);

ALTER TABLE "Codes"."VehicleColor" OWNER TO postgres;

ALTER TABLE "Codes"."VehicleColor" ALTER COLUMN "ID" ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME "Codes"."VehicleColor_ID_seq"
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);

ALTER TABLE ONLY "Codes"."VehicleColor"
ADD CONSTRAINT "VehicleColor_pkey" PRIMARY KEY ("ID");

SELECT pg_catalog.setval('"Codes"."VehicleColor_ID_seq"', 1, true);

With this last line Select pg_catalog.setval... table VehicleColor PK order was 1,3,5,6,7.. and without this last line, PK order is 1,3,4..

Does anyone has idea why this happens?

Lube
  • 318
  • 1
  • 12

0 Answers0