PostgreSQL MySQL 兼容性之 - 数字类型

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)]
时间: 2024-08-03 12:28:55

PostgreSQL MySQL 兼容性之 - 数字类型的相关文章

PostgreSQL MySQL 兼容性之 - 字符串类型

char MySQL [NATIONAL] CHAR[(M)] [CHARACTER SET charset_name] [COLLATE collation_name] A fixed-length string that is always right-padded with spaces to the specified length when stored. M represents the column length in characters. The range of M is 0

PostgreSQL MySQL 兼容性之 - Gis类型

PostGIS的GIS功能相比MySQL强大太多,本文仅仅列举了MySQL支持的部分.欲了解PostGIS请参考:http://postgis.net/docs/manual-2.2/reference.htmlPostGIS有几百个操作函数, 对GIS支持强大. POINT MySQL POINT PointFromText('POINT(10 10)') PointFromWKB(AsWKB(PointFromText('POINT(10 20)')) PostgreSQL # Postgr

PostgreSQL MySQL 兼容性之 - 时间类型

DATE MySQL DATE A date. The supported range is '1000-01-01' to '9999-12-31'. '0000-00-00' is a permitted special value (zero-date), unless the NO_ZERO_DATE SQL_MODE is used. Also, individual components of a date can be set to 0 (for example: '2015-00

详解MySQL数据类型之数字类型正确使用

无论是在小得可怜的免费数据库空间或是大型电子商务网站,合理的设计表结构.充分利用空间是十分必要的.这就要求我们对数据库系统的常用MySQL数据类型有充分的认识.下面我就将我的一点心得写出来跟大家分享. MySQL数据类型之数字类型 数字类型按照我的分类方法分为三类:整数类.小数类和数字类. 我所谓的"数字类",就是指DECIMAL和NUMERIC,它们是同一种类型.它严格的说不是一种数字类型,因为他们实际上是将数字以字符串形式保存的;他的值的每一位(包括小数点)占一个字节的存储空间,因

PostgreSQL MySQL 兼容性之 - 空(NULL)

NULL compare operator <=> MySQL SELECT 99 <=> NULL, NULL <=> NULL; +-------------+---------------+ | 99 <=> NULL | NULL <=> NULL | +-------------+---------------+ | 0 | 1 | +-------------+---------------+ IS NULL IS NOT NULL

PostgreSQL MySQL 兼容性之 - bit 函数和操作符

bit 函数和操作符 MySQL & Bitwise AND << Left shift >> Shift right BIT_COUNT Returns the number of set bits ^ Bitwise XOR | Bitwise OR ~ Bitwise NOT PostgreSQL Operator Description Example Result || concatenation B'10001' || B'011' 10001011 &

PostgreSQL MySQL 兼容性之 - 读写用户的只读影子用户

在一些企业里面,通常会在数据库中创建一些只读用户,这些只读用户可以查看某些用户的对象,但是不能修改或删除这些对象的数据. 这种用户通常可以给开发人员,运营人员使用,或者数据分析师 等角色的用户使用. 因为他们可能关注的是数据本身,并且为了防止他们误操作修改或删除线上的数据,所以限制他们的用户只有只读的权限. MySQL这块的管理应该非常方便. 其实PostgreSQL管理起来也很方便. 用户可以先参考我前面写的两篇文章 PostgreSQL 逻辑结构 和 权限体系 介绍 https://yq.a

PostgreSQL MySQL 兼容性之 - 自增值

AUTO_INCREMENT , sequence MySQL AUTO_INCREMENT The AUTO_INCREMENT attribute can be used to generate a unique identity for new rows. When you insert a new record to the table, and the auto_increment field is NULL or DEFAULT, the value will automatical

二进制-mysql 数据库中 blob 类型存储数字 无法正常插入更新

问题描述 mysql 数据库中 blob 类型存储数字 无法正常插入更新 事情是这样的,在Mysql数据库中有个字段是blob类型的,里面存放的是 8字节无符号整数, 类似于 33454690,45672389,这样一类数值,我使用select 语句select conv(hex(bc.DataTimeStamp) ,16,10) as DataTimestamp 是可以正常显示的,现在我想把 33454690 这个数字 查找出来,加1,变为 33454691,再存放回去. 使用语句 inser