I have a query:
SELECT …
FROM …
WHERE project = 123
AND (
file = file1 and fieldidx = idx1
OR file = file2 and fieldidx = idx2
OR …)
… I want to create the where clause in a function that has the required array of tuples, where the tuple is a user type (file text, idx smallint).
I don’t know how (I’m trying to avoid using a union).
2
Answers
You don’t need a function to do that. Just check whether the tuple is in the provided array:
or
Create a PostgreSQL function that takes an array of user-defined tuples and uses the
"unnest"
function to compare values and construct the desiredWHERE
clause.1. Create a user-defined type
2.After it, Create the PostgreSQL function like below:
This function, you can pass an array of
"file_idx_type"
tuples as an argument,
and it will be used to construct the
WHERE
clause in your main query without using UNION.I hope this gonna work..
#Apache-Age #postgrsql #psql