I am creating Postgresql prepared statement as follows.
PREPARE fetch_users AS SELECT *
FROM "user" u
WHERE
u.email = $1
LIMIT 1;
It is getting successfully created, and I can see it in the pg_prepared_statements
table.
But, when I do,
EXECUTE fetch_users('testemail@test.com');
I'm getting no result from the database, although the select query returns the result when run independently.
Am I using prepared statements correctly?
Note: I am using PostgreSQL version: 15.1
with Dbeaver. When I run the prepared statement I get this prompt.
I enter nothing for the value and select Ok
. When the statement gets executed, this is the output.
It seems the null is inserted in the prepared statement.
in the prompt, you need to click on the ignore button:
This way it will not put any predefined parameter values in your prepared statements.