Closed Alice52 closed 3 years ago
á
占 2 字节Name | Aliases | Description |
---|---|---|
bit [ (n) ] | fixed-length bit string | |
boolean | bool | logical Boolean (true/false) |
bytea | binary data (“byte array”) | |
smallint | int2 | signed two-byte integer |
integer | int, int4 | signed four-byte integer |
bigint | int8 | signed eight-byte integer |
real | float4 | single precision floating-point number (4 bytes) |
double precision | float8 | double precision floating-point number (8 bytes) |
numeric [ (p, s) ] | decimal[(p, s)] | exact numeric of selectable precision |
character [ (n) ] | char [ (n) ] | fixed-length character string |
character varying [ (n) ] | varchar [ (n) ] | variable-length character string |
timestamp [ (p) ] [ without time zone ] | date and time (no time zone) | |
date | calendar date (year, month, day) | |
json | textual JSON data | |
jsonb | binary JSON data, decomposed | |
serial | serial4 | autoincrementing four-byte integer |
uuid | universally unique identifier | |
cidr | IPv4 or IPv6 network address | |
--------------------- | ------------- | --------------------- |
bigserial | serial8 | autoincrementing eight-byte integer |
bit varying [ (n) ] | varbit [ (n) ] | variable-length bit string |
box | rectangular box on a plane | |
circle | circle on a plane | |
inet | IPv4 or IPv6 host address | |
interval [ fields ] [ (p) ] | time span | |
line | infinite line on a plane | |
lseg | line segment on a plane | |
macaddr | MAC (Media Access Control) address | |
macaddr8 | MAC (Media Access Control) address (EUI-64 format) | |
money | currency amount | |
path | geometric path on a plane | |
pg_lsn | PostgreSQL Log Sequence Number | |
pg_snapshot | user-level transaction ID snapshot | |
point | geometric point on a plane | |
polygon | closed geometric path on a plane | |
smallserial | serial2 | autoincrementing two-byte integer |
text | variable-length character string | |
time [ (p) ] [ without time zone ] | time of day (no time zone) | |
time [ (p) ] with time zone | timetz | time of day, including time zone |
timestamp [ (p) ] with time zone | timestamptz | date and time, including time zone |
tsquery | text search query | |
tsvector | text search document | |
txid_snapshot | user-level transaction ID snapshot (deprecated; see pg_snapshot) | |
xml | XML data |
-- 将中国时区的时间 '2022-02-12 04:16:58' 转换为时间戳
select EXTRACT(epoch FROM CAST('2022-02-12 04:16:58' AS TIMESTAMP) at time zone 'Asia/Shanghai');
type
int type:
unsigned
t1
tinyint(1) unsigned zerofill NOT NULL DEFAULT '0':0 到 255
ZEROFILL: 显示宽度, 不够时前面补 0
char & varchar & nvarchar: 查询时会忽略最后的空格
char(n): 效率
如果字符集是 **-bin 则区分大小写
后面
的空格, 存储时会存储前面空格, 后面不满的用空格字符补足[n]varchar(n): 空间
后面
的空格, 存储时会存所有的空格varchar &
nvarcharALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
varchar 不能存储 Unicode 字符集数据(使用的是 8-bit 的 codepage), 节约空间选择: char vs varchar
{不要使用nvarchar}
json
generated column
字段存储 json 中的某个值: 可以在此基础上创建索引date-time
datetime & date & timestamp
DEFAULT CURRENT_TIMESTAMP | ON UPDATE CURRENT_TIMESTAMP
{可以考虑使用时间戳(4字节)-unix_timestamp}
, mysql 可以使用8位存储同意解决这个问题结论: 优先使用 Timestamp
mysql and jdbc:
serverTimezone
超重要best practice
int 的不好点
apply
IPv4 地址使用 UNSIGNED INT
ipv6 使用 varbinary