2

I'm converting a SQL Server stored procedure to HiveQL.

How can I convert something like:

SELECT * FROM table1 WHERE id NOT IN (7,6,5,4,2,12)
some guy
  • 682
  • 2
  • 7
  • 16
MBZ
  • 26,084
  • 47
  • 114
  • 191

3 Answers3

5

NOT IN is now supported in Hive. See https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF.

Solomon
  • 946
  • 14
  • 18
2

Try this:

SELECT * FROM table1 WHERE NOT array_contains(array(7,6,5,4,2,12), id)
thyme
  • 480
  • 7
  • 16
  • upvoting because NOT ARRAY_CONTAINS solves another problem of neither A nor B should be present in an array.. like NOT ARRAY_CONTAINS(Array, A) and NOT ARRAY_CONTAINS(Array, B) – Shubham Patel Nov 17 '21 at 18:04
-4

According to the documentation it says you can use not in:

The negated forms can be written as follows:

from DomesticCat cat where cat.name not between 'A' and 'B'

from DomesticCat cat where cat.name not in ( 'Foo', 'Bar', 'Baz' )

Are you getting an error when you try your query in the question?

Please try based on the references as well.

Community
  • 1
  • 1
bonCodigo
  • 14,268
  • 1
  • 48
  • 91