What exactly is `returnGeneratedKeys` from the opt...
# komapper
s
What exactly is
returnGeneratedKeys
from the options here
onDuplicateKeyUpdate().multiple().options
supposed to do? The query still returns a single Long value. Essentially I'm trying to bulk insert and retrieve all IDs with postgresql
and the batch method sadly isn't available for the postgres driver
so ideally there would be an option for the returning keyword
t
If you are using PostgreSQL, this option is rarely useful. However, SQL Server, for example, does not support returning the ID generated by bulk insert. So you need to set the returnGeneratedKeys option to
false
for a successful bulk insert.
s
I see. so the only two options are script query or look through multiple executeAndGet to achieve what I want?
t
Hmmm. As far as I know, PostgreSQL returns all generated IDs with bulk insert. Can you show me your code?
s
Copy code
QueryDsl.insert(table).onDuplicateKeyUpdate(table.userId, table.title).multiple(entities)
returns a Long of how many columns have been inserted/updated
Copy code
insert into table (userId, title) values(a, b) returning id
is what I'm looking for
t
I see. I had inadvertently forgotten that you are using onDuplicateKeyUpdate. In that case, you certainly need to use either script query or executeAndGet. Currently Komapper does not support the returning keyword.
s
yeah I need it for this query. I guess the loop will do for now, thank you