1

I have an array of the form :

myArray = ["1234-56", "1234-567"]

My table has a column which is constructed exactly like the array and consists of a string array, we call the column : myColumn.

I want to output the rows where , one or more values of the arrays match.

My current attempt was the following :

SELECT *
FROM myTable
WHERE myColumn && myArray;

But this ends with the following error message:

ERROR: Column "56" does not exist.
2
  • It seems you are not passing the array constant properly from within your code. What are you using? Java? C++? C#? Please edit your question and add the code that runs your query. Commented Jun 21, 2020 at 13:44
  • The Array comes from JavaScript. The Code that runs my query is above. Commented Jun 21, 2020 at 13:52

1 Answer 1

2

A string in double quotes is an “identifier” in SQL, that is the name of a table, column, function or other object.

So when you write

SELECT * FROM mytable
WHERE mycolumn && ARRAY["56","95"];

PostgreSQL will identify "56" as a column name (it couldn't be a table in that context), and it complaint that table mytable has no column called 56.

The solution is to mark 56 as a string literal, that is, surround it with single quotes:

SELECT * FROM mytable
WHERE mycolumn && ARRAY['56','95'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.