How can I set a size limit for an “int” datatype in PostgreSQL 9.5

后端 未结 2 1636
长情又很酷
长情又很酷 2020-12-10 18:31

I am experimenting with PostgreSQL coming from SQL using MySQL and I simply wish to create a table with this piece of code which is valid SQL:

CREATE TABLE f         


        
2条回答
  •  渐次进展
    2020-12-10 18:33

    The answer is that you use numeric or decimal types. These are documented here.

    Note that these types can take an optional precision argument, but you don't want that. So:

    CREATE TABLE flat_10
    (
      pk_flat_id DECIMAL(30) DEFAULT 1,
      rooms      DECIMAL(10) NOT NULL,
      room_label CHAR(1) NOT NULL,
    
      PRIMARY KEY (pk_flat_id)
    );
    

    Here is a SQL Fiddle.

    I don't think that Postgres supports unsigned decimals. And, it seems like you really want serial types for your keys and the long number of digits is superfluous.

提交回复
热议问题