Ah that sounds like a good tip (there I was hacking away at a proc).
So I've re-formulated it like this:
Field<String> allocated = ALLOCATIONS.NUMBER.min().as("allocated");
String number = db.execute(ctx -> {
String sql = ctx.insertInto(PRIMARY_ASSIGNMENTS,
PRIMARY_ASSIGNMENTS.REGISTRANT, PRIMARY_ASSIGNMENTS.NUMBER).
select(
ctx.select(DSL.val(registrant), allocated).
from(ALLOCATIONS).
where(ALLOCATIONS.NUMBER.notIn(
ctx.select(ASSIGNMENTS.NUMBER).
from(ASSIGNMENTS)
).and(ALLOCATIONS.REGISTRANT.eq(registrant)))
).getSQL();
return ctx.fetch("{0} RETURNING {1}", sql,
allocated.getName()).getValue(1, allocated);
});
But I seem to be getting a binding error:
SQL [? RETURNING ?]; ERROR: syntax error at or near "$1"
Am I forgetting to bind the query parameters somewhere?
On Wed, May 20, 2015 at 3:31 PM, Lukas Eder <[email protected]> wrote:
> Yes, but you don't have to do everything with plain SQL. You can do this:
>
> DSL.using(configuration)
> .fetch("{0} returning {1}", theSelect, theField);
>
>
> 2015-05-20 16:23 GMT+02:00 Ben Hood <[email protected]>:
>>
>> Hi Lukas,
>>
>> Good to know that a fix in the pipeline - I guess for now I should
>> just write this query in plain SQL?
>>
>> Ben
>>
>> On Wed, May 20, 2015 at 3:17 PM, Lukas Eder <[email protected]> wrote:
>> > Hi Ben,
>> >
>> > Yes, that's too bad. The INSERT .. SELECT API has a couple of flaws.
>> > This
>> > particular flaw, I've just fixed recently for jOOQ 3.7:
>> > https://github.com/jOOQ/jOOQ/issues/3779
>> >
>> > Unfortunately, it won't be available for earlier versions...
>> >
>> > Cheers,
>> > Lukas
>> >
>> > 2015-05-20 16:13 GMT+02:00 Ben Hood <[email protected]>:
>> >>
>> >> Hi Lukas,
>> >>
>> >> I can't seem to find the API to do an INSERT RETURNING using a SELECT,
>> >> for example:
>> >>
>> >> db.execute(ctx ->
>> >> ctx.insertInto(PRIMARY_ASSIGNMENTS, PRIMARY_ASSIGNMENTS.REGISTRANT,
>> >> PRIMARY_ASSIGNMENTS.NUMBER).
>> >> select(
>> >> ctx.select(DSL.val(registrant), ALLOCATIONS.NUMBER.min()).
>> >> from(ALLOCATIONS).
>> >> where(ALLOCATIONS.NUMBER.notIn(
>> >> ctx.select(ASSIGNMENTS.NUMBER).
>> >> from(ASSIGNMENTS)
>> >> ).and(ALLOCATIONS.REGISTRANT.eq(registrant)))
>> >> ).
>> >> execute()
>> >> );
>> >>
>> >> I was poking for some kind of returning() thingy, as you can use on a
>> >> InsertValuesStepN.
>> >>
>> >> Or is it more idiomatic to do a plain jane
>> >>
>> >> ctx.insertInto().
>> >> values(
>> >> ctx.select().stuff().here()).
>> >> returning(
>> >> field().from().stuff()
>> >> )
>> >>
>> >> ?
>> >>
>> >> Cheers,
>> >>
>> >> Ben
>> >>
>> >> --
>> >> 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.
>> >
>> >
>> > --
>> > 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.
>>
>> --
>> 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.
>
>
> --
> 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.
--
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.