postgres
postgres copied to clipboard
Escaping parameters ($1, $2,...) when creating SQL functions
Hi all,
I am looking for the right way to escape $1, $2,...
, when used inside a CREATE FUNCTION
statement.
As a minimal example, let's say we have this query in a file:
CREATE OR REPLACE FUNCTION "sample_function"(integer) RETURNS boolean
AS
$$
SELECT CASE WHEN $1 > 15 THEN true ELSE false END AS x FROM (VALUES (1)) AS y
$$
LANGUAGE SQL
STABLE
RETURNS NULL ON NULL INPUT
How should I escape $$
and $1
in this example?
Thank you a lot in advance for your help!
I don't understand your question. Where is the value being passed in for the parameter $1. Can you please write out the entire javascript instead of just the sql part?
I could be wrong but I feel you trying to ask a generic PostgreSQL question? If so you should be asking ask on the PostgreSQL mailing list or their slack channel. This is the repo for "postgres.js" , a javascript client library for PostgreSQL.