Closed ohmree closed 3 years ago
I think that ON CONFLICT (song_url) DO NOTHING
means the return type is nullable, meaning fetch_optional
would be required.
I don't think that this is a tide-sqlx
issue, perhaps try asking in the SQLx discord.
You're right, my bad.
The correct way to do what I was trying to do is as follows:
INSERT INTO song_urls (song_url)
VALUES ($1)
ON CONFLICT (song_url) DO UPDATE
SET song_url=EXCLUDED.song_url
RETURNING id
And I must say I didn't suspect the issue was in the DO NOTHING
clause, thanks for pointing me the correct way and saving me a whole bunch of time :)
I'm using postgres 13.1, rust nightly and these relevant crates:
Here's the SQL that was used to create my table:
And here's the erroneous code, along with the error from the logging middleware:
The route in question responds to
PUT
methods, which from a (very) quick look at the tide-sqlx code I see isn't considered safe (and therefore uses a transaction, am I correct?).I should note that before using this crate I used plain sqlx without transactions, just a regular
PgPool
.Now I'm very much a noob when it comes to SQL (I didn't even know about transactions before coming across this project) but I think that this might be a syntax thing, maybe for for some reason values can't be returned like this from transactions (which explains why the code worked before when I used plain sqlx)?
I've also tried using
fetch_optional
, which as expected returns a future that resolves toOk(None)
.