Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

column type in PostgreSQL for floating numbers and integers

Tags:

postgresql

I have a column in Postgres where data looks something like this: 1.8, 3.4, 7, 1.2, 3 So it has floating numbers in it as well as integers... What would be the right type for this kind of column?

Numeric data type ?

like image 350
gurbajani Avatar asked Oct 15 '25 07:10

gurbajani


1 Answers

Here is a similar question: Data types to store Integer and Float values in SQL Server

Numeric should work!

Another option is to use a VARCHAR column, and store a character representation of the value.

But it seems that you would need some type of indicator as to which type of value was stored. And there's several drawbacks to this approach. One big drawback is that these would allow for "invalid" values to be stored.

Another approach would be to use two columns, one of them INTEGER, the other FLOAT, and specify a precedence, and allow a NULL value in the INTEGER column to represent that the value was stored in the FLOAT column.

For all datatypes in SQL look here: Data types to store Integer and Float values in SQL Server

like image 188
JulianBPL Avatar answered Oct 17 '25 23:10

JulianBPL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!