question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable insert auto increment key

See original GitHub issue

Version

io.vertx:vertx-pg-client:4.0.0

Context

Unable insert auto increment key

CREATE TABLE books
(
    id    SERIAL PRIMARY KEY,
    title VARCHAR(50) NOT NULL
);

INSERT INTO books (id, title)
VALUES (1, 'The Catcher in the Rye'),
       (2, 'Nine Stories'),
       (3, 'Franny and Zooey'),
       (4, 'The Great Gatsby'),
       (5, 'Tender id the Night'),
       (6, 'Pride and Prejudice'),
       (7, 'Professional ASP.NET 4.5 in C# and VB');
====================================================================================================
18:44:19.956 [Test worker] DEBUG io.github.zero88.jooq.vertx.QueryHelper - DEFAULT:             insert into "public"."books" ("title") values (?) returning "public"."books"."id", "public"."books"."title"
18:44:19.957 [Test worker] DEBUG io.github.zero88.jooq.vertx.QueryHelper - NAMED:               insert into "public"."books" ("title") values (:1) returning "public"."books"."id", "public"."books"."title"
18:44:19.957 [Test worker] DEBUG io.github.zero88.jooq.vertx.QueryHelper - INLINED:             insert into "public"."books" ("title") values ('abc') returning "public"."books"."id", "public"."books"."title"
18:44:19.958 [Test worker] DEBUG io.github.zero88.jooq.vertx.QueryHelper - NAMED_OR_INLINED:    insert into "public"."books" ("title") values ('abc') returning "public"."books"."id", "public"."books"."title"
18:44:19.958 [Test worker] DEBUG io.github.zero88.jooq.vertx.QueryHelper - INDEXED:             insert into "public"."books" ("title") values (?) returning "public"."books"."id", "public"."books"."title"
18:44:19.959 [Test worker] DEBUG io.github.zero88.jooq.vertx.QueryHelper - FORCE_INDEXED:       insert into "public"."books" ("title") values (?) returning "public"."books"."id", "public"."books"."title"
18:44:19.959 [Test worker] DEBUG io.github.zero88.jooq.vertx.QueryHelper - POSTGRESQL:          insert into "public"."books" ("title") values ($1) returning "public"."books"."id", "public"."books"."title"

{ "message": "duplicate key value violates unique constraint \"books_pkey\"", "severity": "ERROR", "code": "23505", "detail": "Key (id)=(1) already exists.", "file": "nbtinsert.c", "line": "427", "routine": "_bt_check_unique", "schema": "public", "table": "books", "constraint": "books_pkey" }
io.vertx.pgclient.PgException: { "message": "duplicate key value violates unique constraint \"books_pkey\"", "severity": "ERROR", "code": "23505", "detail": "Key (id)=(1) already exists.", "file": "nbtinsert.c", "line": "427", "routine": "_bt_check_unique", "schema": "public", "table": "books", "constraint": "books_pkey" }
	at io.vertx.pgclient.impl.codec.ErrorResponse.toException(ErrorResponse.java:31)
	at io.vertx.pgclient.impl.codec.QueryCommandBaseCodec.handleErrorResponse(QueryCommandBaseCodec.java:57)
	at io.vertx.pgclient.impl.codec.ExtendedQueryCommandCodec.handleErrorResponse(ExtendedQueryCommandCodec.java:90)
	at io.vertx.pgclient.impl.codec.PgDecoder.decodeError(PgDecoder.java:236)
	at io.vertx.pgclient.impl.codec.PgDecoder.decodeMessage(PgDecoder.java:122)
	at io.vertx.pgclient.impl.codec.PgDecoder.channelRead(PgDecoder.java:102)
	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:748)

Do you have a reproducer?

  • Link to github project/gist

Extra

Fedora 32, openjdk 8

I think it seems blocker/major issue

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
zero88commented, Mar 1, 2021

Ah, I knew a reason. When setup init data, I added manual id and postgresql is not able to cover as normal sequence. lastval() still is 0 after initialized data. then I need to correct sequence in init data step.

Closed it due to invalid. Thanks for your support

0reactions
zero88commented, Mar 1, 2021

Even try, still no luck

insert into "public"."books" ("id", "title") values (default, $1) returning "public"."books"."id", "public"."books"."title"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to add primary key/unique key/auto-increment to this ...
The only way that I know of is dropping the table and recreating it, this way the auto increment would start taking the...
Read more >
Cannot insert a value for auto-increment primary key #1195
I'm getting the error Cannot insert a value for auto-increment primary key (...) when I'm trying to write a row to a MySQL...
Read more >
Upsert fails and not respecting auto increment on primary key
As I understand your issue, you are trying to perform Upsert in SQL table which is having PersonID as identity column . However,...
Read more >
How are auto_increment keys handled in INSERT (SELECT ...
You can insert into an auto-increment column and specify a value. This is fine; it simply overrides the auto-increment generator.
Read more >
Insert statement for auto increment column - Vertica Forum
Nan, Do you want to insert NULL value in Primary Key Column? Mayank's response is right. When you have an Auto_increment column, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found