New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RETURNING syntax #5
Comments
This seems like a good idea. The thing I'm thinking about is how to keep it portable, since the syntax across MySQL and Postgres differs on this point. What DB are you using? |
Postgres.MySQL doesn't have this problem I think. They use the stock LastInsertID or some such... Jeremy From: Ben HoodSent: Saturday, December 20, 2014 5:08 PMTo: relops/sqlcReply To: relops/sqlcCc: Jeremy ShuteSubject: Re: [sqlc] RETURNING syntax (#5)This seems like a good idea. The thing I'm thinking about is how to keep it portable, since the syntax across MySQL and Postgres differs on this point. What DB are you using? —Reply to this email directly or view it on GitHub. |
Of course the next issue that you run into is that Postgres will allow a lot more than just the id in a |
Yeah I don't actually think this is that simple. When you have a fluent I don't think RETURNING is valid in MySQL for instance. I'm not sure what the "right" thing to do in this case is... Perhaps a Jeremy On Sat, Dec 20, 2014 at 6:13 PM, Ben Hood notifications@github.com wrote:
|
To my knowledge, only PostgreSQL and Firebird have this syntax. Oracle has it, but only in PL/SQL, not in SQL, and DB2 can emulate it like so: SELECT id FROM FINAL TABLE(INSERT INTO t VALUES(...)) SQL Server knows the Then, of course, there is also the possibility of multi-row-insert: INSERT INTO t VALUES (1, 'a'), (2, 'b'), (3, 'c') RETURNING id;
INSERT INTO t SELECT a, b FROM t2 RETURNING id; And later on, the same can be done with |
@lukaseder As I was writing my last comment, I was thinking, what would JOOQ do, and then speak of the devil :-) So many thanks for sharing your vast experience with us. So what is the idiomatic way of doing this with JOOQ - is there something in the fluent API or do you defer to the driver? |
I've begun some work on this on the returning branch in order to sketch out how this might look, but it's not functional yet. |
I've merged the simplest solution possible that supports Postgres, there are a number of improvements that could be made, but it would be good to get some feedback to see this approach helps at all. |
The fluent API contains a The implementation, however, is driver-specific, indeed. The Open Source implementations can be seen here: grep for |
Many thanks for the heads up - having a reference implementation is a very good thing :-) |
Woohoo. jOOQ is a reference implementation ;-) Just ping me if you have any questions! |
Closing this issue seeing as it has long since been implemented. |
it'd be really nice to be able to automatically produce syntax RETURNING id. i can hack around it with other methods for now.
The text was updated successfully, but these errors were encountered: