New answers tagged

2

Use this query instead: SELECT path, markdown FROM public."Comment" WHERE path = $1 AND ($2 IS NULL OR markdown = $2); To ignore the second parameter, pass NULL for it. Recent related question with more info: Conditional WHERE in plpgsql function


1

What language are you calling the query from? I've used query builders to add additional criteria to a base query. In this case, the query builder would add the check on markdown only if there was a value to compare it too. The AND markdown = ALL conditional as you describe it is no different that if you had no markdown comparison in the WHERE clause.


2

I do not agree with the approach you are thinking of using, but if you are dead set on using it, then I would probably structure the query like this: SELECT path, markdown FROM public."Comment" where path = '/other/relative/path/' AND (TRUE OR markdown = 'here I am'); Essentially adding a 3rd parameter to your query .. one use case would use the 3rd ...


0

With that many values you are likely to run into estimation errors during query plan generation. This will lead to it choosing worse (slower-performing) plans than it might otherwise. With that many values I would suggest INSERTing them into an actual table, with index(es), which is JOINed to in the query. Logically the two are the same. Practically, ...



Top 50 recent answers are included