postgresql—-字符串函数与操作符详解数据库
数据库postgresql 详解 函数 字符串 8212 操作符
2023-06-13 09:20:11 时间
替换字符串,其中第一个int是开始位置,第二个int是长度,如果没有第二个int则长度默认为第二个字符串的长度
select overlay( Txxxxas placing hom from 2 for 4);
Thomas
替换字符串,将第一个字符串中的第二个字符串替换成第三个字符串 select replace( Txxxxas , xxxx , hom ); Thomas
把string中from字符替换成对应to中的字符,如( text , tx , nd )中t- n,x- d,替换后结果为nedn;如果from比to长,则删除from多出的字符,如( Txxxxas , Txas , hom )结果为hooom;如果from中有重复字符,对应顺序也是一一对应的,但是重复字符以第一个为准,如( txxxa , xxx , abcd ),结果为taaad
截取匹配posix正则表达式的字符串,for为转移字符 select substring( Thomas from %# o_a# _ for # );
删除字符串头部(leading),尾部(trailing)或两边的空白活[characters]字符 select trim(both x from xxjdhdxxxx );
格式化字符串,类似C语言的sprintf,其中n$表示第n个参数 select format( Hello %s, %1$s , World ); Hello World, World
返回字符串前n个字符,n为负数时返回除最后|n|个字符以外的所有字符 select left( hello ,-2);
返回字符串后n个字符,n为负数时返回除最前|n|个字符意外的所有字符 select right( hello ,2);
在字符串开头填充text至长度为length,缺省为空白,如果string的长度已经大于length,则会截断后面多余length的字符 select lpad( 123 ,5, 0 ); 00123
在字符串尾部填充text至长度为length,缺省为空白,如果string的长度已经大于length,则会截断后面多余length的字符 select rpad( he ,1, o );
返回适合SQL语句标志符且使用适当引号的字符串,在字符串两端加双引号,如果字符串中出现双引号,返回结果中将变成两个,如果有2个连续的单引号,返回时只有1个 select quote_ident( Foo bar ); Foo bar
将字符串string以delimiter进行分割,并返回第field个子串 select split_part( 1#2#3 , # ,2);
regexp_split_to_array(stringtext, pattern text [, flags text]) text[] 将字符串匹配posix正则表达式分割为字符串数组 select regexp_split_to_array( hello world , E //s+ ); {hello,world}
regexp_matches(string text,pattern text [, flags text]) setof text[] 返回string中第一个匹配posix正则表达式的子串,如果flag=g,则返回所有 select regexp_matches( foobarbequebaz , (b..) , g );
替换字符串,将第一个字符串中的第二个字符串替换成第三个字符串 select replace( Txxxxas , xxxx , hom ); Thomas
把string中from字符替换成对应to中的字符,如( text , tx , nd )中t- n,x- d,替换后结果为nedn;如果from比to长,则删除from多出的字符,如( Txxxxas , Txas , hom )结果为hooom;如果from中有重复字符,对应顺序也是一一对应的,但是重复字符以第一个为准,如( txxxa , xxx , abcd ),结果为taaad
select translate( Txxxxas , xxxxa , hom );
select translate( Txxxxas , Txas , hom );
select translate( txxxa , xxxa , abcd );
select substring( hello world from 2 for 3);
select substring( hello world from 2);
截取匹配posix正则表达式的字符串,for为转移字符 select substring( Thomas from %# o_a# _ for # );
删除字符串头部(leading),尾部(trailing)或两边的空白活[characters]字符 select trim(both x from xxjdhdxxxx );
格式化字符串,类似C语言的sprintf,其中n$表示第n个参数 select format( Hello %s, %1$s , World ); Hello World, World
返回字符串前n个字符,n为负数时返回除最后|n|个字符以外的所有字符 select left( hello ,-2);
返回字符串后n个字符,n为负数时返回除最前|n|个字符意外的所有字符 select right( hello ,2);
在字符串开头填充text至长度为length,缺省为空白,如果string的长度已经大于length,则会截断后面多余length的字符 select lpad( 123 ,5, 0 ); 00123
在字符串尾部填充text至长度为length,缺省为空白,如果string的长度已经大于length,则会截断后面多余length的字符 select rpad( he ,1, o );
parse_ident(qualified_identifiertext [,
strictmode booleanDEFAULT true ] )
text[] 将qualified_identifier拆分解析到一个数组中,以句点为分隔符。 select parse_ident( SomeSchema.someTable ); {someschema,sometable}返回适合SQL语句标志符且使用适当引号的字符串,在字符串两端加双引号,如果字符串中出现双引号,返回结果中将变成两个,如果有2个连续的单引号,返回时只有1个 select quote_ident( Foo bar ); Foo bar
将字符串string以delimiter进行分割,并返回第field个子串 select split_part( 1#2#3 , # ,2);
regexp_split_to_array(stringtext, pattern text [, flags text]) text[] 将字符串匹配posix正则表达式分割为字符串数组 select regexp_split_to_array( hello world , E //s+ ); {hello,world}
regexp_matches(string text,pattern text [, flags text]) setof text[] 返回string中第一个匹配posix正则表达式的子串,如果flag=g,则返回所有 select regexp_matches( foobarbequebaz , (b..) , g );
{bar}
{beq}
{baz}
regexp_replace(string text,pattern text,
replacement text[, flags text])
将匹配posix正则表达式的第一个子串替换成指定字符串,如果flag=g,则替换所有 select regexp_replace( Thomas , .[mN]a. , M );格式说明符由 % 字符引进,格式为
%[ position ] type
组件的字段有:
position (optional)
n$ 格式的字符串,这里的n是要打印的参数的索引。索引为1表示在formatstr之后的第一个参数。如果省略了position,默认使用序列中的下一个参数。
type (required)
格式转换的类型用来产生格式说明符的输出。支持下列的类型:
s 格式参数值为简单的字符串。空值作为空字符串对待。
I 将参数值作为SQL标识符对待,如果需要,双写它。值为空是错误的。
L 引用参数值作为SQL文字。空值用字符串 NULL 显示,没有引用。
除了上述的格式说明符,特殊的序列 %% 可以用作输出 % 字符。
示例:
test=# SELECT format(Hello %s, World); format ------------- Hello World (1 row) test=# SELECT format(Testing %s, %s, %s, %%, one, two, three); format ---------------------------- Testing one, two, three, % (1 row) test=# SELECT format(INSERT INTO %I VALUES(%L), Foo bar, EO/Reilly); format ------------------------------------------- INSERT INTO "Foo bar" VALUES(OReilly) (1 row)
4864.html
相关文章
- python-Python与PostgreSQL数据库-处理PostgreSQL查询结果
- 详解PostgreSQL 数据库跨版本升级常用方案对比
- postgresql 数据库中的 序列nextval 使用方法详解
- 用PostgreSQL数据库做地理位置app应用
- PostgreSQL常用命令详解数据库
- postgresql数据库和mysql数据库的对比分析详解数据库
- pg_ctl — 启动、停止、重启 PostgreSQL详解数据库
- PostgreSQL 设置允许访问IP详解数据库
- PostgreSQL继承详解数据库
- postgresql—-COPY之表与文件之间的拷贝详解数据库
- POSTGRESQL 锁表的问题详解数据库
- postgresql 查询某一个表中的所有字段详解数据库
- postgresql – 事务详解数据库
- 优化实现PostgreSQL缓存优化,更高性能!(postgresql缓存)
- PostgreSQL快速导入SQL文件(postgresql导入sql文件)
- 创建PostgreSQL数据库序列的实践(postgresql序列)
- Python如何连接PostgreSQL数据库?(python连接postgresql)
- PostgreSQL 接口:连接数据库的必备工具(postgresql接口)
- PostgreSQL中文手册详解数据库操作技巧(postgresql中文手册)
- 深入浅出PostgreSQL(postgresql书籍)
- PostgreSQL测试:深入了解数据库运行状况(postgresql测试)
- PostgreSQL连接的实践与思考(postgresql链接)
- PostgreSQL查看数据库,索引,表,表空间大小的示例代码
- 15个postgresql数据库实用命令分享