Skip to content
Advertisement

Multi-column IN/ANY postgres query

Sample table schema:

Requirement: Fetch rows that match any of the tuples (col1, col2) presented in an array.

SQL:

I want to write this query in Go using the “database/sql” package with “github.com/lib/pq” driver, and that is where I am facing the problem.

I can easily do this for single column IN/ANY query.

for example, the following query

can be achieved with the following code snippet:

However, I could not use similar approach for multi-column query. I tried passing pq.Array([][]string), pq.Array([]*pq.StringArray) etc. as argument, but they do not work, and fetches the following error:

Will appreciate any help on this.

Advertisement

Answer

You could do the following:


For a two-column tuple you should be able to do the following:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement