Skip to content
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

Getting number of rows inserted from Table.insert or Table.insertIgnore? #851

Closed
glasser opened this issue Mar 28, 2020 · 2 comments
Closed

Comments

@glasser
Copy link

glasser commented Mar 28, 2020

Sometimes I run Table.insertIgnore and want to know whether I did indeed insert a row (on Postgres).

insertIgnore seems to return the InsertStatement rather than the count of rows:

fun <T:Table> T.insertIgnore(body: T.(UpdateBuilder<*>)->Unit): InsertStatement<Long> = InsertStatement<Long>(this, isIgnore = true).apply {
    body(this)
    execute(TransactionManager.current())
}

Am I missing some way of getting the return value of execute out of this? Should I just be creating an InsertStatement myself and executing it if I want that?

@maxwell-carbon
Copy link

+1 to this, the main alternative I see is to execute an additional query first to see if the potentially-conflicting row already exists, but I'd prefer not to do that.

@Tapac
Copy link
Contributor

Tapac commented Aug 4, 2021

InsertStatement (and all inheritors) will get insertedCount field in the next release. The field will contain the inserted rows size provided by the driver.

@Tapac Tapac closed this as completed Aug 4, 2021
SchweinchenFuntik pushed a commit to SchweinchenFuntik/Exposed that referenced this issue Oct 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants