How to set size limit for int data type in PostgreSQL 9.5

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

CREATE TABLE flat_10
(
  pk_flat_id INT(30) DEFAULT 1,
  rooms      INT(10) UNSIGNED NOT NULL,
  room_label CHAR(1) NOT NULL,

  PRIMARY KEY (flat_id)
);

I get an error

ERROR:    syntax error at or near "("
LINE 3:   pk_flat_id integer(30) DEFAULT 1,

I searched the Internet and could not find the answer, and I cannot find the answer in the PostgreSQL manual. What am I doing wrong?

I clearly want to set a limit on the number of digits that can be inserted in the pk_flat_id field

+4
source share
2 answers

I clearly want to set a limit on the number of digits that can be inserted in the pk_flat_id field

" " - . MySQL int .

2147483647 int(1) .

, integer, :

CREATE TABLE flat_10
(
  pk_flat_id bigint DEFAULT 1,
  rooms      integer NOT NULL,
  room_label CHAR(1) NOT NULL,

  PRIMARY KEY (flat_id), 
  constraint valid_number 
      check (pk_flat_id <= 999999999)
);
+5

, numeric decimal. .

, , . :

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)
);

- SQL.

, Postgres . , , , .

+2

Source: https://habr.com/ru/post/1625000/


All Articles