Please take this survey to help us learn more about how you use third party tools. Your input is greatly appreciated!

How can I CAST a numeric column to a NUMERIC with different precision and/or scale?

edited August 2020 in General Discussion

As part of integrating a new system we're focusing on dumping the information as PARQUET files but found out there is a limitation on precision and scale for NUMERIC fields. We thought about casting but can't figure out the syntax correctly and couldn't find anything online beyond altering the values in the table with an add/alter dance

Answers

  • Jim_KnicelyJim_Knicely Administrator

    Like this?

    dbadmin=> \d t
                                        List of Fields by Tables
     Schema | Table | Column |     Type      | Size | Default | Not Null | Primary Key | Foreign Key
    --------+-------+--------+---------------+------+---------+----------+-------------+-------------
     public | t     | c      | numeric(10,5) |    8 |         | f        | f           |
    (1 row)
    
    dbadmin=> SELECT c, c::NUMERIC(7, 2) FROM t;;
          c      |    c
    -------------+----------
     10021.23212 | 10021.23
       102.22823 |   102.23
         0.23100 |     0.23
    (3 rows)
    
    
  • Thanks! I was using the CAST and didn't think about changing the format

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file

Can't find what you're looking for? Search the Vertica Documentation, Knowledge Base, or Blog for more information.