Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL - change precision of numeric?

Tags:

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?

like image 438
Andrius Avatar asked Feb 12 '14 11:02

Andrius


People also ask

How do I change precision 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.

What is numeric precision in PostgreSQL?

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.

How do I change data to numeric in PostgreSQL?

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.


2 Answers

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.

like image 71
huzeyfe Avatar answered Sep 19 '22 19:09

huzeyfe


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.

like image 24
Maike Mota Avatar answered Sep 19 '22 19:09

Maike Mota