https://www.runoob.com/postgresql/postgresql-functions.html

点击跳转到菜鸟教程

长度-length

select length('aa-bb-cc') // 8

替换-replace

// '-'替换为''
select replace('aa-bb-cc','-','') // aabbcc

字符串分割

-- 字符串被分成3部分,取最后一部分,那最后一个参数就是3
select split_part('aa-bb-cc' ,'-', 3)  // cc

字符所在下标位置-position

select  position('f' in 'abcdef') // 6

字符串截取-substring

select SUBSTRING('abcd',2); // bcd,下标从1开始,从2截取到末尾
select substring('abcd',2,1); // b,下标从1开始,从2截取1个字符

md5

SELECT md5('abc') // 900150983cd24fb0d6963f7d28e17f72

时间戳转换为标准时间

SELECT to_timestamp(1634634710) //2021-10-19 09:11:50+00

json内部增删改

// 修改json内部单个字段
update tablename set aaa = aaa::jsonb || '{"isbool": false}'::jsonb where id = '999'


// 搭配使用,如果传过来的aaa='{}',那么就不做修改。否则传过来的值做修改
update tablename
   set bbb = 1
      ,aaa = case when $1::character varying = '{}' then aaa::jsonb || '{}'::jsonb else  aaa::jsonb || $1::jsonb end
 where user_id = 888
   and id = 999

// json整体修改
update tablename set aaa = '{"aaa": "bbb"}'::jsonb where id = '999'

update user_bike_map set security_custom = security_custom::jsonb || '{"quietDefence": false}'::jsonb

相关文章:

  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-18
  • 2021-06-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2022-02-18
  • 2022-02-28
  • 2021-07-16
相关资源
相似解决方案