0

In a hive table how can I add the '-' sign in a field, but for random records? If I use the syntax below it changes all the records in the field to negative, but I want to change random records to negative.

This is the syntax I used which changed all the records to negative:

CAST(CAST(-1 AS DECIMAL(1,0)) AS DECIMAL(19,2)) 
*CAST(regexp_replace(regexp_replace(TRIM(column name),'\\-',''),'-','') as decimal(19,2)),
Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Syed
  • 1

1 Answers1

0

If you want to change random values to negative, why not use a case expression?

select (case when rand() < 0.5 then - column_name else column_name end)

Despite your query, this assumes that the column is a number of some sort, because negating strings doesn't make much sense.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786