Reputation: 5704
I want to run a query like this where params
is a text
array:
select * from table_name where params[10]<>'Retail'
"Give me rows whose params array does not contain the value Retail at index 10"
There are several rows that should statisfy that condition, i.e. they have something other than 'Retail' at that array index. But still I get 0 rows.
However, if I do
select * from table_name where params[10]='Retail'
Then I get rows as expected i.e. non 'Retail' rows are filtered out.
Also, select params[10] from table_name
gives a number of rows with values like
{Retail}
{HNI}
Where as I am expecting:
Retail
HNI
This tells me, I am getting an array instead of a the value at that index. How do I extract the raw text value from an array so that I can use it in where clause etc.?
Postgres version: 13.1
Client: DBeaver 7.0.0
Upvotes: 0
Views: 480
Reputation: 222682
I suspect you want is distinct from
instead if <>
, so null
values are properly handled, as well as arrays that have less than 10 elements:
select * from table_name where params[10] is distinct from 'Retail'
Upvotes: 3