天天看点

SQL:pgSQL截取查询结果

使用​​split_part(string text, delimiter text2, field int)​​以字符为标识截取

其中:

  1. text 为截取字段
  2. text2 为截取标识符:按照什么形式切割(比如逗号’,’)
  3. int 为删除项目的位置:位置从1开始

举例:查询一个满足条件的灾害点图片

select image from geohazard_all_english where x =  '110.31417' and y = '30.63582' and type = '地面沉降' and date = '201912'      
SQL:pgSQL截取查询结果

由图可知,查询结果有多个,且通过​

​,​

​分割,因此使用​

​split_part​

select split_part(image,',',1) as image from geohazard_all_english where x =  '110.31417' and y = '30.63582' and type = '地面沉降' and date = '201912'      
SQL:pgSQL截取查询结果

使用​​substr(text,int 4,int 4)​​可以截取特定位置之间的字符