java - returning a value with jOOQ and PostgreSQL serial and RETURNING -


i have postgresql uris table serial (autoincrementing) uri_id column , string uri column. can query table fine using jooq:

createdslcontext().select(fieldbyname("uri_id")).from(tablebyname("uris"))     .where(fieldbyname("uri").equal(uri.tostring())).fetchone(0, integer.class)) 

that returns java integer. when insert new uri, want generated uri_id key, try this:

createdslcontext().insertinto(tablebyname("uris"), fieldbyname("uri"))     .values(uri.tostring()).returning(fieldbyname("uri_id")).fetchone().getvalue(0, integer.class) 

this time error:

exception in thread "main" java.lang.illegalargumentexception: field 0 not contained in list 

just test, tried supplying literal value uri_id in insert statement, still got error.

it looks correct sql being generated:

insert "uris" ("uri") values ('http://example.com/') returning "uri_id" 

but returned record empty. true when specify literal uri_id in insert statement.

how can retrieve auto-generated column postgresql insert statement using jooq?

this question being discussed more in detail on jooq user group.

essentially, you're running known issue returning clause not supported jooq 3.3 (and lower) when used plain sql, instead of generated tables. issue reference:

https://github.com/jooq/jooq/issues/2374


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -