Impala Query: Find value in pipe-separated list

SummerEla

I have a column containing rows of pipe separated STRING values:

|   colA    |
 ___________
| 5|4|2|255 |
| 5|4|4|0   |
| 5|4|4|3   |
| 5|4|4|4   |

I need to create a query that will select all rows that contain 4 or 5, but never 2 or 3. Something along the lines of:

SELECT t.colA
FROM my_table t
WHERE (t IN ("4", "5") AND t NOT IN ("2","3")

Resulting in:

|   colA    |
 ___________
| 5|4|4|0   |
| 5|4|4|4   |

I ended up using a combination of the two answers below, as using either method alone still left me with rows containing only "255". Here's the final query:

SELECT t.colA
FROM my_table t
WHERE (t.colA IN ('4', '5') OR t.colA LIKE "%|5|%" 
       OR t.colA LIKE "%|5" OR t.colA LIKE "5|%")
AND t.colA NOT LIKE "%3%"    
AND t.colA NOT LIKE "%|2|%" 
AND t.colA NOT REGEXP "^2|%" 
AND t.colA NOT REGEXP "%|2$"

There is probably a more elegant way to do this, but that does the trick.

Steven

What about using the LIKE function ?

where (t like  '%4%' or t like  '%5%')
and (t not like  '%2%' and t not like  '%3%')

That should do the job.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Impala regex to find "2", but not "255", in pipe-delimited list

From Dev

Find value in comma-separated list

From Dev

Find string value in comma-separated list

From Dev

Using Linq to find a value in comma separated value in a List

From Dev

How to write SQL query to get column wise comma separated value list from record

From Dev

How do I pipe a newline separated list as arguments to another command?

From Dev

How do I pipe a newline separated list as arguments to another command?

From Dev

Extracting a string value from a pipe-separated string in a table column

From Dev

How to get all values from a variable made of value separated by a pipe ( | )?

From Dev

Fill empty cell in pipe-separated-value file with default text

From Dev

Displaying the following query as a comma separated list

From Dev

mongodb how to return list of value only from find query

From Dev

MongoDB Query : Find where key's value from list of values

From Dev

mongodb how to return list of value only from find query

From Dev

jQuery find elements then make into comma separated list

From Dev

Find Nth item in comma separated list in Python

From Dev

How to query a string value separated by comma in MySQL?

From Dev

Check if value exists in a comma separated list

From Dev

Regular Expression for last value in comma separated list

From Dev

Turn a value range in a cell into a comma separated list

From Dev

Splitting a column value into list of values separated by comma

From Dev

Turn a value range in a cell into a comma separated list

From Dev

Find query result to List

From Dev

MYSQL Query to find the value

From Dev

Describe Impala Query Metadata

From Dev

Query Porting to Impala

From Dev

Query Porting to Impala

From Dev

Query to find all couples of countries separated by another nation

From Dev

Find a value in a list of dicts

Related Related

  1. 1

    Impala regex to find "2", but not "255", in pipe-delimited list

  2. 2

    Find value in comma-separated list

  3. 3

    Find string value in comma-separated list

  4. 4

    Using Linq to find a value in comma separated value in a List

  5. 5

    How to write SQL query to get column wise comma separated value list from record

  6. 6

    How do I pipe a newline separated list as arguments to another command?

  7. 7

    How do I pipe a newline separated list as arguments to another command?

  8. 8

    Extracting a string value from a pipe-separated string in a table column

  9. 9

    How to get all values from a variable made of value separated by a pipe ( | )?

  10. 10

    Fill empty cell in pipe-separated-value file with default text

  11. 11

    Displaying the following query as a comma separated list

  12. 12

    mongodb how to return list of value only from find query

  13. 13

    MongoDB Query : Find where key's value from list of values

  14. 14

    mongodb how to return list of value only from find query

  15. 15

    jQuery find elements then make into comma separated list

  16. 16

    Find Nth item in comma separated list in Python

  17. 17

    How to query a string value separated by comma in MySQL?

  18. 18

    Check if value exists in a comma separated list

  19. 19

    Regular Expression for last value in comma separated list

  20. 20

    Turn a value range in a cell into a comma separated list

  21. 21

    Splitting a column value into list of values separated by comma

  22. 22

    Turn a value range in a cell into a comma separated list

  23. 23

    Find query result to List

  24. 24

    MYSQL Query to find the value

  25. 25

    Describe Impala Query Metadata

  26. 26

    Query Porting to Impala

  27. 27

    Query Porting to Impala

  28. 28

    Query to find all couples of countries separated by another nation

  29. 29

    Find a value in a list of dicts

HotTag

Archive