SQL Server 与 PostgreSQL 数据类型映射关系

Microsoft SQL Server PostgreSQL
BIGINT 64-bit integer BIGINT
BINARY(n) Fixed length byte string BYTEA
BIT 1, 0 or NULL BOOLEAN
CHAR(n) Fixed length char string, 1 <= n <= 8000 CHAR(n)
VARCHAR(n) Variable length char string, 1 <= n <= 8000 VARCHAR(n)
VARCHAR(max) Variable length char string, <= 2GB TEXT
VARBINARY(n) Variable length byte string , 1 <= n <= 8000 BYTEA
VARBINARY(max) Variable length byte string , <= 2GB BYTEA
NVARCHAR(n) Variable length Unicode UCS-2 string VARCHAR(n)
NVARCHAR(max) Variable length Unicode UCS-2 data, <= 2GB TEXT
TEXT Variable length character data, <= 2GB TEXT
NTEXT Variable length Unicode UCS-2 data, <= 2GB TEXT
DOUBLE PRECISION Double precision floating point number DOUBLE PRECISION
FLOAT§ Floating point number DOUBLE PRECISION
INTEGER 32 bit integer INTEGER
NUMERIC(p,s) Fixed point number NUMERIC(p,s)
DATE Date includes year, month and day DATE
DATETIME Date and Time with fraction TIMESTAMP(3)
DATETIME2§ Date and Time with fraction TIMESTAMP(n)
DATETIMEOFFSET§ Date and Time with fraction and time zone TIMESTAMP§ WITH TIME ZONE
SMALLDATETIME Date and Time TIMESTAMP(0)
TINYINT 8 bit unsigned integer, 0 to 255 SMALLINT
UNIQUEIDENTIFIER 16 byte GUID(UUID) data CHAR(16)
ROWVERSION Automatically updated binary data BYTEA
SMALLMONEY 32 bit currency amount MONEY
IMAGE Variable length binary data, <= 2GB BYTEA

以下在实际项目中应用的,可作参考,如果有纰漏麻烦指正!

  • datetime 改为 timestamp(0)
  • int 改为 int8
  • chinese_prc_ci_as 改为 “pg_catalog”.“default”
  • float(53) 改为 decimal(35,15)
  • nvarchar 改为 varchar

猜你喜欢

转载自blog.csdn.net/londa/article/details/108181328