1
CREATE TABLE SampleMath
(m  NUMERIC (10,3),
 n  INTEGER,
 p  INTEGER);

Question: why there is a space between NUMERIC and (10,3).

At first, I thought (10,3) is a column constraint. However, it doesn't seem to be correct as common constraints are NOT NULL, UNIQUE as listed here.

Then I thought that it could be the property (precision, scale) for the datatype NUMERIC as described in the documentation. In that case, I think there should not be a space between NUMERIC and (10,3). I also tried to delete the space in between and it seems the code still works. In my understanding, if it is the property, there should not be a space, which makes me really confused.

Any help to clarify this would be really appreciated. Thanks for your help in advance.

3
  • SQL allows spaces between most operators and identifies, including between a type and its length (or precision and scale). Commented Sep 21, 2019 at 20:08
  • Thanks. Didn't know this before. Now everything is more clear to me. Commented Sep 21, 2019 at 20:16
  • . . I should add that newlines and tabs are also allowed. Most languages work like this. Commented Sep 21, 2019 at 20:25

1 Answer 1

5

NUMERIC (10,3) is a datatype. It can store a number with a total of 10 digits (that's called precision), including 3 decimal (aka scale, ie the count of digits at the right of the decimal point). So basically the biggest number that it can store is 9999999.999.

The space between NUMERIC and the definition of its scale and precision is not meaningful. Even a new line would be OK, like:

CREATE TABLE SampleMath
(m  NUMERIC 
        (10,3),
 n  INTEGER,
 p  INTEGER);
Sign up to request clarification or add additional context in comments.

2 Comments

Do you mean that it would be better to delete the space between NUMERIC and (10,3). One follow-up question is why SQL doesn't raise an error if we add it, as it could have confused (10,3) as a constraint.
I mean that this space has no meaning for Postgres. You can have no space, one space, several spaces, that does not make a difference at all. About constraints, they have a different syntax, there is no risk of confusion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.