2019独角兽企业重金招聘Python工程师标准>>>
PostgreSQL支持3种字符串类型,分别是character varying(n)、character(n)和text,character varying(n)可以写成varchar(n),character(n)可以写成char(n),最大长度1GB,text最大长度无限制。n是实际字符数量。
大部分情况下,推荐使用text和varchar(n)。
PostgreSQL支持一种二进制类型bytea。
二进制数据有图片(JPG、PNG等)、音乐(MP3、WMA等)格式文件,和字符串文件区别在于文本文件需要复合文件编码和储存可见字符,二进制文件没有类似限制,字符串适合储存文本文件。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19---字符串练习 postgres=# create table testtext(testtext char(2),testvarchar varchar(3), testchar text); CREATE TABLE postgres=# postgres=# postgres=# insert into testtext values('1','111','111'),('0','000','011777'); INSERT 0 2 postgres=# select * from testtext; testtext | testvarchar | testchar ----------+-------------+---------- 1 | 111 | 111 0 | 000 | 011777 (2 行记录) postgres=#
插入长度超过预定值是,提示错误信息。
下面演示部分常见字符串函数。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13---字符串拼接 postgres=# select 'N'||'O'; ?column? ---------- NO (1 行记录) postgres=# select 'Hello'||' '||'World'; ?column? ------------- Hello World (1 行记录) postgres=#
根据以上代码字符串可以拼接2个以上字符串。
复制代码
1
2
3
4
5
6
7
8---1Byte=8Bite postgres=# select bit_length('A'); bit_length ------------ 8 (1 行记录) postgres=#
检查字符串byte长度。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12postgres=# select char_length('A'); char_length ------------- 1 (1 行记录) postgres=# select char_length('Hello world.'); char_length ------------- 12 (1 行记录) postgres=#
字符串转换为小写。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12postgres=# select lower('Hello'); lower ------- hello (1 行记录) postgres=# select lower('HI'); lower ------- hi (1 行记录) postgres=#
字符串转换为大写。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12postgres=# select upper('Hello'); upper ------- HELLO (1 行记录) postgres=# select upper('Hi'); upper ------- HI (1 行记录) postgres=#
转载于:https://my.oschina.net/u/1011130/blog/1568102
最后
以上就是乐观跳跳糖最近收集整理的关于PostgreSQL数据类型-二进制数据和字符串数据类型与字符串函数的全部内容,更多相关PostgreSQL数据类型-二进制数据和字符串数据类型与字符串函数内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复