0
votes

While SELECT'ing columns in Vertica, it shows normal numeric values:

SELECT nvl2(exposure_time_ms, ROUND(exposure_time_ms / 1000, CASE WHEN exposure_time_ms < 10000 THEN 1 ELSE 0 END), 0) :: numeric(12,1) AS exposure_seconds

1

But when I am inserting the same thing to the table, which has column 'exposure seconds' type NUMERIC(12,1), it changes all digits after the decimal point to 0:

2

1
Can you post what value exposure_time_ms contains? Also show us the insert query? - akshay

1 Answers

0
votes

Presumably, this is because the nvl2() calculation produces an integer. So, try this:

SELECT nvl2(exposure_time_ms,
            ROUND(exposure_time_ms / 1000.0,
                  CASE WHEN exposure_time_ms < 10000 THEN 1 ELSE 0 END
                 ), 0
           )::numeric(12,1) AS exposure_seconds

I will say that it really doesn't make sense to round the values based on the magnitude. You should store the value "as is" and use rounding for presentation -- if it is really needed.