https://kotlinlang.org logo
#komapper
Title
# komapper
s

S.

01/13/2023, 2:58 PM
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

Toshihiro Nakamura

01/13/2023, 3:28 PM
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

S.

01/13/2023, 3:33 PM
I see. so the only two options are script query or look through multiple executeAndGet to achieve what I want?
t

Toshihiro Nakamura

01/13/2023, 3:38 PM
Hmmm. As far as I know, PostgreSQL returns all generated IDs with bulk insert. Can you show me your code?
s

S.

01/13/2023, 3:40 PM
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

Toshihiro Nakamura

01/13/2023, 3:47 PM
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

S.

01/13/2023, 9:27 PM
yeah I need it for this query. I guess the loop will do for now, thank you
19 Views