天天看點

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)​​可以截取特定位置之間的字元