Closed YoelisA closed 2 months ago
Hello and welcome to SQLPage !
What you found is a common caveat with postgres. Other databases such as SQLite cast the values automatically. Unfortunately, I don't think there is much more to do than better documentation and better error messages. HTTP URL parameters are not typed, and there is no easy way to automatically guess that $id should be an integer in this context...
Do you have a suggestion concerning the documentation ?
Thank you :)
I didn't understand that it was postgres that is responsible for type checking the url parameters. I tried to do the query with an int and text from psql and postgres was able to delete the resource so I assumed it was something with sqlpage.
I'm not sure for the documentation, maybe the examples could be categorized with the database behind ?
Yes, I would like to improve https://sql.ophir.dev/your-first-sql-website/
What could we have written that would have made it obvious to you how URL parameters binding work ? Can we change something in the existing tutorial or docs to make them less confusing ?
If you have suggestions, feel free to open a pr on https://github.com/lovasoa/SQLpage/blob/main/examples/official-site/your-first-sql-website/tutorial.md
And in general, I would love to know how you approached discovering sqlpage, getting started, and using the different features. It would help prioritize the work on the docs.
Introduction
When no type is specified, the casting of the url parameters passed to a query fails with
DELETE FROM <table> WHERE id = CAST($1 AS TEXT) RETURNING 'resource deleted'
. DB is postgres hosted on supabase.To Reproduce
create
delete_todo.sql
withhttp://localhost:8080/delete_todo.sql?id=1
Actual behavior
Backtrace says :
Screenshots
If applicable, add screenshots to help explain your problem.
Expected behavior
I expected a deletion of the resource without the need the specify the id's type. If it's needed for some reason, maybe we should find a caveat in the documentation ?
Version information
Additional context
To fix this error, I had to specify the id's type with
$id::int