I have a web application in java and it uses a query. I don't want to write the query into Java, so I made a function:
CREATE OR REPLACE FUNCTION testFunc(inputs text) RETURNS TABLE(...) AS
$$
SELECT .... FROM ...
JOIN ...
where true
;
$$
LANGUAGE SQL;
I want the Function parameter INPUTS to also be in the WHERE clause so if inputs is
AND speed = 0 AND ....
Where clause looks like
where true AND speed = 0 AND ...
How can i achieve this?
EDIT
Also it is acceptable to have many parameters (a int, b string, c string ..) but then i need to have
WHERE speed = * AND stop = * AND ...
which is not acceptable. How can i achieve this ?
OR can i put a if statement inside it ? Like
Select .. . from ...
JOIN ...
WHERE true
IF (a != null){AND speed = $1}
IF ....
;
SELECT * FROM myView WHERE speed = 4