Closed ashleyrdudek closed 4 years ago
The issue here is that .single_value
returns a nullable value, because the subquery could return no value. You id
column is not nullable, therefore the error. The same workaround as mentioned in #1918 also applies here.
In an upsert query, a null index would result in inserting a new entry with a newly generated index. The documentation/guide says that replace_into
is equivalent to an upsert statement, but is lacking this functionality. Are there any plans on expanding replace_into
's functionality in the future?
Could you link the relevant Sqlite documentation here? I did not found anything about this yesterday on a quick search.
Apologies, I totally misspoke! I meant INSERT OR REPLACE
, not upsert 🤦♀, here is some documentation for that. It looks like there was an issue for postgres and sqlite INSERT OR REPLACE
statements a loooong time ago, but they didn't mention anything about nullable values back then. Here's a little playground I made with this example. Sorry again for saying the wrong thing! I'll definitely be cringing at that mistake for many days to come 😅
The linked example does not contain any sort of specification saying what is the behaviour in the null
case. Is there anything in the sqlite documentation about this?
Here is the replace page, it links to the on conflict page that shows its functionality.
Setup
Versions
Feature Flags
Problem Description
What are you trying to accomplish?
I am trying to use
single_value()
on a replace statement for a non-nullable value. I understand why this is an issue with insert statements (seen in #1918) butreplace_into()
is an upsert statement for sqlite. Using the following SQL table and command successfully upserts a table entry in SQLite:Here are some snippets of my code (again, very similar to #1918)
The error I get is:
At first, I was confused because the expected type is
Nullable
. I proceeded to add thenullable()
function to thesingle_value
statement, but I got the same issue. When I replace thesingle_value
statement to a reference to a random integer (&42
for example). The code compiles.Checklist