pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: sivapostgres@yahoo.com <sivapostgres@yahoo.com>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re:  Behavior of identity columns
Date: Thu, 4 Aug 2022 08:52:08 +0000 (UTC)
Message-ID: <253496326.523793.1659603128227@mail.yahoo.com> (raw)
References: <253496326.523793.1659603128227.ref@mail.yahoo.com>

Hello,
I see 'identity' column values increment even when some error(s) occurs while inserting data.  Is that a known bug or known behavior?
Create script of table:**************************** CREATE TABLE public.users(    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),    username character varying(255) COLLATE pg_catalog."default",    email character varying(255) COLLATE pg_catalog."default",    first_name character varying(255) COLLATE pg_catalog."default",    last_name character varying(255) COLLATE pg_catalog."default",    CONSTRAINT users_pkey PRIMARY KEY (id),    CONSTRAINT "test_UX" UNIQUE (username))WITH (    OIDS = FALSE)TABLESPACE pg_default;
ALTER TABLE public.users    OWNER to postgres;***********************************column id is int and identity columncolumn username is unique 
When I insert data that violates the unique constraint, I see that the id value gets incremented. And I see missing values in between when I add the correct data next time.
my Insert SQLinsert into users (username, email, first_name, last_name) values ('ONE', 'one@gmail.com', 'one', '1'); // id = 1insert into users (username, email, first_name, last_name) values ('ONE', 'one@gmail.com', 'one', '1'); // Insert failsinsert into users (username, email, first_name, last_name) values ('TWO', 'one@gmail.com', 'one', '1'); // id = 3insert into users0(username, email, first_name, last_name) values ('TWO', 'one@gmail.com', 'one', '1'); // insert fails as there is no users0 tableinsert into users (username, email, first_name, last_name) values ('THREE', 'one@gmail.com', 'one', '1'); // id = 5
ID gets incremented even when some wrong table name is mentioned in the query. Check 4th query.
Is it a known behavior or a known bug?

Happiness AlwaysBKR Sivaprakash

view thread (2+ messages)  latest in thread

Message-ID: <253496326.523793.1659603128227@mail.yahoo.com>
Permalink:  ../253496326.523793.1659603128227@mail.yahoo.com/
Also on:    postgresql.org/message-id/253496326.523793.1659603128227@mail.yahoo.com

 · 

reply

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: sivapostgres@yahoo.com
  Subject: Re: Behavior of identity columns
  In-Reply-To: <253496326.523793.1659603128227@mail.yahoo.com>
  References: <253496326.523793.1659603128227.ref@mail.yahoo.com> <253496326.523793.1659603128227@mail.yahoo.com>

* 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