سؤال

I have coordinates with the type double precision in a column. I want to check the length (it has to be 7) before the decimal point (before the decimal places). The numbers can have decimals up to 4.

My first idea:

CHECK (char_length(point_gauss::double precision::char)=...
هل كانت مفيدة؟

المحلول

For floating point keep in mind these are binary floating point types and so decimal precision is a bit of a problematic concept. Your first instinct should be something like:

 CHECK(point_gauss BETWEEN -9999.999 AND 9999.999)

However, if you need specific base 10 precision the best way is to change from double to numeric and use this instead:

 point_gauss NUMERIC(7,3),....
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top