1

I have a code that inserts a new row and returns its ID:

transaction {
    val id = Comments.insert {
        it[this.postId] = postId
        it[msg] = comment.msg
        it[this.createdBy] = createdBy
    } get Comments.id
}

However, how can I return all values, not just ID? In SQL I would write a something as below:

INSERT INTO comments (post_id, msg, created_by)
VALUES (?, ?, ?)
RETURNING id, post_id, msg, created_by, created_at;
Denis Sologub
  • 7,277
  • 11
  • 56
  • 123
  • @МихаилНафталь yeah, this is that I need! Thank you! It's little weird that I could not find that topic in Google. – Denis Sologub Jan 24 '22 at 02:53

1 Answers1

2

Specifying custom RETURNING clause is currently not supported by Exposed DSL.

There are some workarounds in this issue: https://github.com/JetBrains/Exposed/issues/1271

If you're willing to run native SQLs, then here's how: Is there a way to run raw sql with Kotlin's Exposed library

Alexey Soshin
  • 16,718
  • 2
  • 31
  • 40