Skip to main content
Question

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

  • August 19, 2020
  • 2 replies
  • 14 views

smontiel

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

2 replies

Jim_Knicely
Forum|alt.badge.img+2
  • Participating Frequently
  • August 19, 2020

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)


smontiel
  • Author
  • New Participant
  • August 19, 2020

Thanks! I was using the CAST and didn't think about changing the format