--
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 jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I think you didn't read the manual. Read chapter 6 of jooq manual and you see how generate tables and sequences.
Everyone, I really need an answer to this quickly.
In another table I had a workaround in that I would query the URI value, which was unique, and it would return me the ID. Very inefficient, but workable.
But now I have another table that does not have any unique values other than the generated ID. So if RETURNING doesn't work, how can I find out the ID that was generated?
I should be able to use CURRVAL, and indeed DSLContext seems to have a currval(), but it requires a Sequence. Where do I get a sequence? I don't seem to be able to do this:
...sequenceByName("entity_id")
It seems there is also a LASTVAL, but DSLContext doesn't have a lastVal(). It has a lastID(), but the documentation says it is not supported on PostgreSQL.
I try to manually execute CURRVAL after an insert:
dslContext.resultQuery("select CURRVAL(uriid)").fetch()
That gives me: ERROR: column "uriid" does not exist
So I try to indicate a table:dslContext.resultQuery("select CURRVAL(uriid) from uris").fetch()
I get: ERROR: could not open relation with OID 1
Maybe it's because jOOQ automatically closed the connection after the previous INSERT.
I think I'm going to have to throw in the towel for the day. I need some direction here.
I just need the generated sequence value. I'm getting the feeling that with normal SQL this would be a piece of cake. Why is jOOQ making it harder than SQL?
I should be able to use CURRVAL, and indeed DSLContext seems to have a currval(), but it requires a Sequence. Where do I get a sequence? I don't seem to be able to do this:
...sequenceByName("entity_id")You're right, this method should be added for API completeness. I have added a feature request for this:As a workaround, you can instanciate the internal (but public) type org.jooq.impl.SequenceImpl instead.
As a workaround, you can instanciate the internal (but public) type org.jooq.impl.SequenceImpl instead.
An example implementation of such a workaround can be seen here, in the commit of our recent implementation of DSL.sequenceByName():
Lukas, you might think of adding a utility function that determines a sequence name from its table name and serial column name, as PostgreSQL generates sequence names automatically in the background. Just a suggestion.
You can have more complex DEFAULT expressions in your DDL statement (e.g. combining the value of two sequences, or hashing sequence values). You can also have several sequence-generated values, or you can generate sequence values on INSERT using triggers (which is what you'd do in Oracle). Other databases don't support sequences, but IDENTITY or AUTO_INCREMENT columns.DEFAULT nextval('sequence_name'::regclass)
...
Note, if you were using the code generator, then much of this information would really be available on your tables - e.g. the identity column, in this case.
...
We generally always recommend to use the code generator. You'll get 100s of features that you don't have without it. It's not too late.
You won't regret it, I promise.