PostgreSQLMySQL相容性之-數字型別

德哥發表於2016-03-14

TINYINT

MySQL

  TINYINT[(M)] [UNSIGNED] [ZEROFILL]
  A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.

PostgreSQL

TINYINT 對應 PostgreSQL
  postgres=# create domain tinyint as smallint constraint ck check (value between -127 and 128);
  CREATE DOMAIN
TINYINT [UNSIGNED] 對應 PostgreSQL
  postgres=# create domain utinyint as smallint constraint ck check (value between 0 and 255);
  CREATE DOMAIN

boolean

MySQL

  boolean

PostgreSQL

  boolean

SMALLINT

MySQL

  SMALLINT[(M)] [UNSIGNED] [ZEROFILL]
  A small integer. The signed range is -32768 to 32767. The unsigned range is 0 to 65535.

PostgreSQL

SMALLINT[(M)] 對應 PostgreSQL
  smallint
SMALLINT[(M)] [UNSIGNED] 對應 PostgreSQL
  postgres=# create domain usmallint as int constraint ck check (value between 0 and 65535);
  CREATE DOMAIN

MEDIUMINT

MySQL

  MEDIUMINT[(M)] [UNSIGNED] [ZEROFILL]
  The signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215.

PostgreSQL

MEDIUMINT[(M)] 對應 PostgreSQL
  postgres=# create domain MEDIUMINT as int constraint ck check (value between -8388608 and 8388607);
  CREATE DOMAIN
MEDIUMINT[(M)] [UNSIGNED] 對應 PostgreSQL
  postgres=# create domain UMEDIUMINT as int constraint ck check (value between 0 and 16777215);
  CREATE DOMAIN

INT

MySQL

  INT[(M)] [UNSIGNED]
  INTEGER[(M)] [UNSIGNED] [ZEROFILL]
  When marked UNSIGNED, it ranges from 0 to 4294967295, otherwise its range is -2147483648 to 2147483647 (SIGNED is the default).

PostgreSQL

INT[(M)]  INTEGER[(M)]  對應 PostgreSQL 
  INT
INT[(M)] [UNSIGNED] 對應 PostgreSQL 
INTEGER[(M)] [UNSIGNED] 對應 PostgreSQL 
  postgres=# create domain UINT as int8 constraint ck check (value between 0 and 4294967295);
  CREATE DOMAIN

BIGINT

MySQL

  BIGINT[(M)] [UNSIGNED] [ZEROFILL]
  The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615.

PostgreSQL

BIGINT[(M)]  對應 PostgreSQL 
  BIGINT
BIGINT[(M)] [UNSIGNED] 對應 PostgreSQL 
  postgres=# create domain UBIGINT as numeric(20,0) constraint ck check (value between 0 and 18446744073709551615);
  CREATE DOMAIN

decimal, dec, numeric, fixed

MySQL

  DECIMAL[(M[,D])] [UNSIGNED] [ZEROFILL]
  DEC[(M[,D])] [UNSIGNED] [ZEROFILL]
  NUMERIC[(M[,D])] [UNSIGNED] [ZEROFILL]
  FIXED[(M[,D])] [UNSIGNED] [ZEROFILL]

PostgreSQL

DECIMAL[(M[,D])]  對應 PostgreSQL 
  decimal[(M[,D])]
DECIMAL[(M[,D])] [UNSIGNED] 對應 PostgreSQL 
  postgres=# create domain udecimal as numeric constraint ck check (value >=0);
  CREATE DOMAIN
  # 不能改domain的scale,precise.

FLOAT

MySQL

  FLOAT[(M,D)] [UNSIGNED] [ZEROFILL]

PostgreSQL

FLOAT[(M,D)]  對應 PostgreSQL 
  float4
FLOAT[(M,D)] [UNSIGNED] 對應 PostgreSQL 
  postgres=# create domain ufloat4 as float4 constraint ck check (value >=0);
  CREATE DOMAIN
  # 不能改domain的scale,precise.

DOUBLE

MySQL

  DOUBLE[(M,D)] [UNSIGNED] [ZEROFILL]
  DOUBLE PRECISION[(M,D)] [UNSIGNED] [ZEROFILL]
  REAL[(M,D)] [UNSIGNED] [ZEROFILL]

PostgreSQL

DOUBLE[(M,D)] 
DOUBLE PRECISION[(M,D)] 
REAL[(M,D)]   對應 PostgreSQL 
  float8
DOUBLE[(M,D)] [UNSIGNED]
DOUBLE PRECISION[(M,D)] [UNSIGNED] 
REAL[(M,D)] [UNSIGNED]     對應 PostgreSQL 
  postgres=# create domain ufloat8 as float8 constraint ck check (value >=0);
  CREATE DOMAIN
  # 不能改domain的scale,precise.

bit

MySQL

  BIT[(M)]
  A bit-field type. M indicates the number of bits per value, from 1 to 64. The default is 1 if M is omitted.

PostgreSQL

  BIT[(M)]


相關文章