I tried to post this earlier but it disappeared; sorry if it shows up
twice. I also posted it elsewhere<http://stackoverflow.com/q/23064480/421049>
.
I have a PostgreSQL `uris` table with serial (autoincrementing) `uri_id`
column and string `uri` column. I can query the table fine using jOOQ:
createDSLContext().select(fieldByName("uri_id")).from(tableByName("uris"))
.where(fieldByName("uri").equal(uri.toString())).fetchOne(0,
Integer.class))
That returns a Java `Integer`. But when I insert a new URI, I want to get
back the generated `uri_id` key, so I try this:
createDSLContext().insertInto(tableByName("uris"), fieldByName("uri"))
.values(uri.toString()).returning(fieldByName("uri_id")).fetchOne().getValue(0,
Integer.class)
This time I get an error:
Exception in thread "main" java.lang.IllegalArgumentException: Field 0
is not contained in list
Just as a test, I tried supplying a literal value for `uri_id` in the
`INSERT` statement, but still got the error.
It looks like the correct SQL is being generated:
insert into "uris" ("uri") values ('http://example.com/') returning
"uri_id"
But the returned record is empty. This is true even when I specify a
literal `uri_id` in the insert statement.
How can I retrieve an auto-generated column from a PostgreSQL `INSERT`
statement using jOOQ?
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.