1、interval类型字段换算成时分秒

date_part('hour', visit_times)*60*60+date_part('minute', visit_times)*60+date_part('seconds', visit_times)

2、计算时间差

to_timestamp(max(ddd),'HH24:MI:SS') -to_timestamp(min(ddd),'HH24:MI:SS')

3、查询jsonb字段中的key对应的值

(detail_jsonb->>'date')::varchar
--detail_jsonb为jsonb类型的字段名,date为其中的key

4、update效率的问题

update table1 set column1=(select column1 from table2) where table2.column2=table1.column2;
update table1 set table1.column1=table2.column1 from (select column1 from table2) where table2.column2=table1.column2;

遇到以上情况,优选第二种方式进行update操作。

5、自增序列取值

nextval('table_seq')

6、和字符串处理相关的函数

函数:string || string 
说明:String concatenation 字符串连接操作

例子:select 'Post' || 'greSQL'; = PostgreSQL

函数:string || non-string or non-string || string

说明:String concatenation with one non-string input 字符串与非字符串类型进行连接操作

例子:select 'Value: ' || 42; = Value: 42

函数:bit_length(string)

说明:Number of bits in string 计算字符串的位数

例子:select bit_length('pmars') = 40

函数:char_length(string) or character_length(string)

说明:Number of characters in string 计算字符串中字符个数

例子:select char_length('pmars'); = 5

函数:lower(string)

说明:Convert string to lower case 转换字符串为小写

例子:select lower('PmArS'); = "pmars"

函数:octet_length(string)

说明:Number of bytes in string 计算字符串的字节数

例子:select octet_length('我是pmars'); = 11  select octet_length('我');  = 3



函数:overlay(string placing string from int [for int])

说明:Replace substring 替换字符串中任意长度的子字串为新字符串

例子:select overlay('I am pmars' placing 'ming' from 6 for 5); = "I am ming"



函数:position(substring in string)

说明:Location of specified substring 子串在一字符串中的位置

例子:select position('ma' in 'pmars'); = 2



函数:substring(string [from int] [for int])

说明:Extract substring 截取任意长度的子字符串

例子:select substring('topmars' from 3 for 3); = "pma"



函数:substring(string from pattern)

说明:Extract substring matching POSIX regular expression. See Section 9.7 for more information on pattern matching. 利用正则表达式对一字符串进行任意长度的字串的截取

例子:select substring('topmars' from 'p.*$'); = "pmars"



函数:substring(string from pattern for escape)

说明:Extract substring matching SQL regular expression. See Section 9.7 for more information on pattern matching. 利于正则表达式对某类字符进行删除,以得到子字符串

例子:select substring('Thomas' from '%#"o_a#"_' for '#'); = "oma"



函数:trim([leading | trailing | both] [characters] from string) 

说明:Remove the longest string containing only the characters (a space by default) from the start/end/both ends of the string 去除尽可能长开始,结束或者两边的某类字符,默认为去除空白字符,当然可以自己指定,可同时指定多个要删除的字符串

例子:select trim(leading 'p' from 'pmars'); = "mars"



函数:upper(string)

说明:Convert string to uppercase 将字符串转换为大写

例子:select upper('pmars'); = "PMARS"



函数:ascii(string)

说明:ASCII code of the first character of the argument. For UTF8 returns the Unicode code point of the character. For other multibyte encodings. the argument must be a strictly ASCII character. 得到某一个字符的Assii值

例子:select ascii('pmars'); = select ascii('p'); = 112



函数:btrim(string text [, characters text])

说明:Remove the longest string consisting only of characters in characters (a space by default) from the start and end of string 去除字符串两边的所有指定的字符,可同时指定多个字符

例子:select btrim('pmars','prs'); = "ma"



函数:chr(int)

说明:Character with the given code. For UTF8 the argument is treated as a Unicode code point. For other multibyte encodings the argument must designate a strictly ASCII character. The NULL (0) character is not allowed because text data types cannot store such bytes. 得到某ACSII值对应的字符

例子:select chr(65); = A



函数:convert(string bytea, src_encoding name, dest_encoding name) 
说明:Convert string to dest_encoding. The original encoding is specified by src_encoding. The string must be valid in this encoding. Conversions can be defined by CREATE CONVERSION. Also there are some predefined conversions. See Table 9-7 for available conversions. 转换字符串编码,指定源编码与目标编码

例子:select convert('我是pmars_in_utf8', 'UTF8', 'GBK'); = "\316\322\312\307pmars_in_utf8"



函数:convert_from(string bytea, src_encoding name) 
说明:Convert string to the database encoding. The original encoding is specified by src_encoding. The string must be valid in this encoding. 转换字符串编码,自己要指定源编码,目标编码默认为数据库指定编码,

例子:select convert_from('\316\322\312\307pmars','GBK'); = "我是pmars"



函数:convert_to(string text, dest_encoding name) 
说明:Convert string to dest_encoding.转换字符串编码,源编码默认为数据库指定编码,自己要指定目标编码,

例子:select convert_to('我是pmars_in_utf8','GBK'); = "\316\322\312\307pmars_in_utf8"



函数:decode(string text, type text) 
说明:Decode binary data from string previously encoded with encode. Parameter type is same as in encode. 对字符串按指定的类型进行解码

例子:select decode('MTIzAAE=', 'base64'); = "123\000\001"



函数:encode(data bytea, type text) 
说明:Encode binary data to different representation. Supported types are: base64, hex, escape. Escape merely outputs null bytes as \000 and doubles backslashes. 与decode相反,对字符串按指定类型进行编码

例子:select encode('123\000\001','base64'); = "MTIzAAE="



函数:initcap(string)
说明:Convert the first letter of each word to uppercase and the rest to lowercase. Words are sequences of alphanumeric characters separated by non-alphanumeric characters. 将字符串所有的单词进行格式化,首字母大写,其它为小写

例子:select initcap('I AM PMARs'); = "I Am Pmars"



函数:length(string)
说明:Number of characters in string 讲算字符串长度

例子:select length('我是pmars'); = 7



函数:length(stringbytea, encoding name )
说明:Number of characters in string in the given encoding. The string must be valid in this encoding. 计算字符串长度,指定字符串使用的编码

例子:select length('我是pmars','GBK'); = 8



函数:lpad(string text, length int [, fill text]) 
说明:Fill up the string to length length by prepending the characters fill (a space by default). If the string is already longer than length then it is truncated (on the right). 对字符串左边进行某类字符自动填充,即不足某一长度,则在左边自动补上指定的字符串,直至达到指定长度,可同时指定多个自动填充的字符

例子:select lpad('pmars', 10, 'to'); = "tototpmars"



函数:ltrim(string text [, characters text]) 
说明:Remove the longest string containing only characters from characters (a space by default) from the start of string 删除字符串左边某一些的字符,可以时指定多个要删除的字符

例子:select ltrim('pmars','amp'); = "rs"



函数:md5(string)
说明:Calculates the MD5 hash of string, returning the result in hexadecimal 将字符串进行md5编码

例子:select md5('pmars'); = "1018ceb949f1472f7252f7da1f5eff42"



函数:pg_client_encoding()
说明:Current client encoding name 得到pg客户端编码

例子:select pg_client_encoding(); = "UTF8"



函数:quote_ident(string text)
说明:Return the given string suitably quoted to be used as an identifier in an SQL statement string. Quotes are added only if necessary (i.e., if the string contains non-identifier characters or would be case-folded). Embedded quotes are properly doubled. 对某一字符串加上两引号

例子:quote_ident('Foo bar') = "Foo bar"



函数:quote_literal(string text)
说明:Return the given string suitably quoted to be used as a string literal in an SQL statement string. Embedded single-quotes and backslashes are properly doubled. 对字符串里两边加上单引号,如果字符串里面出现sql编码的单个单引号,则会被表达成两个单引号

例子:quote_literal('O\'Reilly') = 'O''Reilly'



函数:quote_literal(value anyelement)
说明:Coerce the given value to text and then quote it as a literal. Embedded single-quotes and backslashes are properly doubled. 将一数值转换为字符串,并为其两边加上单引号,如果数值中间出现了单引号,也会被表示成两个单引号

例子:quote_literal(42.5) = '42.5'



函数:regexp_matches(string text, pattern text [, flags text])
说明:Return all captured substrings resulting from matching a POSIX regular expression against the string. See Section 9.7.3 for more information. 对字符串按正则表达式进行匹配,如果存在则会在结果数组中表示出来

例子:regexp_matches('foobarbequebaz', '(bar)(beque)') = {bar,beque}



函数:regexp_replace(string text, pattern text, replacement text [, flags text])
说明:Replace substring(s) matching a POSIX regular expression. See Section 9.7.3 for more information. 利用正则表达式对字符串进行替换

例子:regexp_replace('Thomas', '.[mN]a.', 'M') = ThM



函数:regexp_split_to_array(string text, pattern text [, flags text ])
说明:Split string using a POSIX regular expression as the delimiter. See Section 9.7.3 for more information. 利用正则表达式将字符串分割成数组

例子:regexp_split_to_array('hello world', E'\\s+') = {hello,world}



函数:regexp_split_to_table(string text, pattern text [, flags text])
说明:Split string using a POSIX regular expression as the delimiter. See Section 9.7.3 for more information. 利用正则表达式将字符串分割成表格

例子:regexp_split_to_table('hello world', E'\\s+') = 

hello

world

(2 rows)



函数:repeat(string text, number int)
说明:Repeat string the specified number of times 重复字符串一指定次数

例子:repeat('Pg', 4) = PgPgPgPg



函数:replace(string text, from text, to text)
说明:Replace all occurrences in string of substring from with substring to 将字符的某一子串替换成另一子串

例子:('abcdefabcdef', 'cd', 'XX') = abXXefabXXef



函数:rpad(string text, length int [, fill text]) 
说明:Fill up the string to length length by appending the characters fill (a space by default). If the string is already longer than length then it is truncated. 对字符串进行填充,填充内容为指定的字符串

例子:rpad('hi', 5, 'xy') = hixyx



函数:rtrim(string text [, characters text])
说明:Remove the longest string containing only characters from characters (a space by default) from the end of string 

去除字符串右边指定的字符

例子:rtrim('trimxxxx', 'x') = trim



函数:split_part(string text, delimiter text, field int)
说明:Split string on delimiter and return the given field (counting from one)  对字符串按指定子串进行分割,并返回指定的数值位置的值

例子:split_part('abc~@~def~@~ghi', '~@~', 2) = def



函数:strpos(string, substring)
说明:Location of specified substring (same as position(substring in string), but note the reversed argument order) 指定字符串在目标字符串的位置

例子:strpos('high', 'ig') = 2



函数:substr(string, from [, count])
说明:Extract substring (same as substring(string from from for count)) 截取子串

例子:substr('alphabet', 3, 2) = ph



函数:to_ascii(string text [, encoding text])
说明:Convert string to ASCII from another encoding (only supports conversion from LATIN1, LATIN2, LATIN9, and WIN1250 encodings) 将字符串转换成ascii编码字符串

例子:to_ascii('Karel') = Karel



函数:to_hex(number int or bigint)
说明:Convert number to its equivalent hexadecimal representation  对数值进行十六进制编码

例子:to_hex(2147483647) = 7fffffff



函数:translate(string text, from text, to text) 
说明:Any character in string that matches a character in the from set is replaced by the corresponding character in the to set 将字符串中某些匹配的字符替换成指定字符串,目标字符与源字符都可以同时指定多个

例子:translate('12345', '14', 'ax') = a23x5

postgresql使用过程中字段转换相关推荐

  1. PostgreSQL 的安装以及在安装过程中遇到的问题及解决方法

    遇到的问题 最近在学习<SQL基础教程>,在安装PostgreSQL的过程中遇到了一些问题,主要有以下两个: There has been an error. Error running ...

  2. 红图新媒体-新媒体,是网络营销过程中的工具

    在没有对网络运营网络营销和新媒体运营过程的相关问题进行细分化讨论和研究的时候.实际上网络营销在实际进行的过程当中,会常常认为新媒体是一种工具,但是在运营新媒体的过程中,我们大多数的人在实际运营过程中都 ...

  3. PbootCMS建站系统日常使用过程中常见问题汇总

    博主抽空整理了一份PbootCMS新手常见问题导航.可以使用Ctrl+F进行搜索查阅. 或者你遇到其他棘手的问题也可以加群交流QQ群:PB教程网交流群,点击即可加入 汇总列表 1.PbootCMS图片 ...

  4. SQL 把表中字段存储的逗号隔开内容转换成列表形式

    原文:[原创]SQL 把表中字段存储的逗号隔开内容转换成列表形式 我们日常开发中,不管是表设计问题抑或是其他什么原因,或多或少都会遇到一张表中有一个字段存储的内容是用逗号隔开的列表. 具体效果如下图: ...

  5. java中时间入数据库格式转换_数据库中字段类型为datetime,转换成java中的Date类型...

    数据类型对照 点击打开链接 JDBC: PreparedStatement ps = conn.prepareStatement(sql); ResultSet rs = ps.executeQuer ...

  6. mysql clob转string_Java获取Oracle中CLOB字段转换成String

    Java获取Oracle中CLOB字段转换成String : try {PreparedStatement stmt = session.connection().prepareStatement(s ...

  7. 【转】继承过程中 父类子类的 字段方法 内存分配 (非java语言)

    名人名言:思想好比火星:一颗火星会点燃另一颗火星.一个深思熟虑的教师和班主任,总是力求在集体中创造一种共同热爱科学和渴求知识的气氛,使智力兴趣成为一些线索,以其真挚的.复杂的关系--即思想的相互关系把 ...

  8. ASP.Net中实现上传过程中将文本文件转换成PDF的方法

    iTextSharp是一个常用的PDF库,我们可以使用它来创建.修改PDF文件或对PDF文件进行一些其他额外的操作.本文讲述了如何在上传过程中将文本文件转换成PDF的方法. 基本工作 在开始之前,我们 ...

  9. java Clob转CLOB_Java获取Oracle中CLOB字段转换成String

    Java获取Oracle中CLOB字段转换成String : try {PreparedStatement stmt = session.connection().prepareStatement(s ...

最新文章

  1. 因特网的域名服务器系统的好处,dns域名服务器的作用是什么
  2. 内含福利 | 世界人工智能大会:对话大咖,深挖机器学习的商业应用
  3. [tool] AI视频翻译 解决英文视频字幕问题(类似youtube自动生成字幕)
  4. Ubuntu用apt-get安装报错:E: Could not get lock /var/lib/dpkg/lock-frontend - open (11:资源暂时不可用)
  5. 修改VMOS2的SID 并成为成员服务器,求助SAS9.4服务器版的sid!!!急急!
  6. 【自译】八步成为数据科学家
  7. 如何设计一款大学生找实习的APP?
  8. android 等待圈_Android ProgressDialog 转圈圈-阿里云开发者社区
  9. opencv 3和qt5计算机视觉应用开发_【资源分享】有哪些学习openCV的网站或书籍?...
  10. 因吵架总被骂,阿里程序猿一气之下发明“情侣吵架神器”
  11. Oracle SQL Developer 调试存储过程步骤(Oracle)
  12. 扫地机器人石头爬坡_都这么强了,还要怎么升级:真实评测石头T6扫地机器人...
  13. POJ 3250 Bad Hair Day - 单调队列
  14. docker 中 NGINX+PHP+MYSQL+REDIS+Elasticsearch 环境搭建 (windows系统)
  15. 丢失控制文件恢复实验记录--4(在线日志文件没有损坏,归档日志丢失,直接重建控制文件(跟踪控制文件trace是旧的情况))...
  16. java事务传播机制事例,spring事务传播机制
  17. Android 开发环境搭建实验报告
  18. python刷博客点击量
  19. chm 乱码 掌阅_chm文件中文乱码问题
  20. 外贸沟通谈判中加分项,这些你都知道吗?

热门文章

  1. 物联网通信协议_物联网架构及五大常用通信协议
  2. 通过mac地址找设备的IP地址
  3. 皇帝内经上关于发梦的解说
  4. 行政区划数据库表结构设计最佳实践
  5. 掌握这几点,年终总结不发愁!
  6. 使用 Stunnel 建立加密隧道
  7. 分道扬镳(DFS+剪枝+邻接表)
  8. python网页版百度_python,_爬虫 页面不存在_百度搜索,python - phpStudy
  9. Docker中搭建RTMP直播流服务器
  10. AcWing 198. [HAOI2007] 反素数 约数个数+dfs