question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to compile InsertStmtImpl(INSERT_STMT)

See original GitHub issue

Build Environment SQLDelight version: 1.4.0 SQLDelight plugin version: 1.4.0 OS: Linux Gradle version: 6.5 Kotlin version: 1.3.72

I just updated to 1.4.0 from 1.3.0 and now my build fails on this statement:

CREATE TABLE MediaError(
  id TEXT AS MediaId PRIMARY KEY NOT NULL REFERENCES Media(id),
  error TEXT AS MediaErrors NOT NULL,
  stacktrace TEXT DEFAULT NULL
);

upsert:
INSERT INTO MediaError(
  id, error, stacktrace
)
VALUES (
  :id, :error, :stacktrace
)
ON CONFLICT(
  id
)
DO UPDATE SET
  error = :error,
  stacktrace = :stacktrace;

The error is:

> Failed to compile InsertStmtImpl(INSERT_STMT): [] :
  INSERT INTO MediaError(
    id, error, stacktrace
  )
  VALUES (
    :id, :error, :stacktrace
  )
  ON CONFLICT(
    id
  )
  DO UPDATE SET
    error = :error,
    stacktrace = :stacktrace

My gradle file:

sqldelight {
  database("MyDatabase") {
    packageName = "com.me.models.sqldelight"
    sourceFolders = listOf("sqldelight-models", "sqldelight-migrations")
    schemaOutputDirectory = file("src/main/sqldelight-migrations")
    dialect = "sqlite:3.24"
  }
}

I tried killing the gradle daemon, and that didn’t help.

If I remove ON CONFLICT... it compiles.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
veyndancommented, Aug 17, 2020

@felipecsl That’s a different issue than the one @eygraber is describing, as the PostgreSQL grammar defined in sql-psi currently does not support upsert (whereas sqlite:3.24 which is being used by @eygraber should be working as it’s defined in the respective sql-psi grammar file).

Please feel free to open a separate issue (ideally in the sql-psi repo) so your issue doesn’t get lost in this one.

0reactions
eygrabercommented, Aug 23, 2020

@AlecStrong this is blocking us from updating to Kotlin 1.4. Any help / pointers would be much appreciated 😄

I tried looking into it myself, and everything works if I change the statement to:

upsert:
INSERT INTO MediaError(
  id, error, stacktrace
)
VALUES (
  :id, :error, :stacktrace
)
ON CONFLICT(
  id
)
DO UPDATE SET
  error = 'error',
  stacktrace = 'some stacktrace';

Obviously that wouldn’t work in reality.

Looking at the stacktrace, it seems like there needs to be another type handled in SqlSetterExpression.argumentType but I’m not sure which one it should be. Maybe UpsertDoUpdate?

Read more comments on GitHub >

github_iconTop Results From Across the Web

INSERT INTO MySQL statement failing [closed] - Stack Overflow
I dug through all of the string manipulation I was doing to dynamically build the query and found that I was using real_escape_string...
Read more >
Why is this insert statement causing an error?
I think it's caused by the mapping, your field Country_of_Origin__c is a lookup field so you should map it to a.Id and not...
Read more >
Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
Read more >
insert (sql) - InterSystems Documentation
Description. The INSERT command inserts a row into a table or uses the results of a SELECT query to insert multiple rows into...
Read more >
2 Server Error Message Reference - MySQL :: Developer Zone
Message: Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found