I tried to change precision like this:
ALTER Table account_invoice ALTER amount_total SET NUMERIC(5);
But I get syntax error, so I'm clearly doing something wrong. What is the right syntax to change precision of numeric in PostgreSQL?
You can use this: ALTER Table account_invoice ALTER amount_total SET DATA TYPE NUMERIC(5,Y); where Y is your required level of precision.
In this syntax, the precision is the total number of digits and the scale is the number of digits in the fraction part. For example, the number 1234.567 has the precision 7 and scale 3 . The NUMERIC type can hold a value up to 131,072 digits before the decimal point 16,383 digits after the decimal point.
Use the :: operator to convert strings containing numeric values to the DECIMAL data type. In our example, we converted the string ' 5800.79 ' to 5800.79 (a DECIMAL value). This operator is used to convert between different data types. It's very popular within PostgreSQL.
Try this:
ALTER Table account_invoice ALTER COLUMN amount_total TYPE DECIMAL(10,5);
DECIMAL(X, Y)
-> X represents full length and Y represents precision of the number.
You can use this:
ALTER Table account_invoice ALTER amount_total SET DATA TYPE NUMERIC(5,Y);
where Y is your required level of precision.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With