1 选择判断

select case 2 when 1 then 'one' when 2 then 'two' else 'more' end union all select case 2 when 1 then 'one' when 2 then 'two' else 'more' end;

2 判断 有点像三元运算符

select case when 1>2 then 'true' else 'false' end;

3 插入和更新二选一

INSERT INTO "fd_question_answer_2WIQRCZAPA" ( ID, uid, title )
VALUES
    ( 21, '9675adb618aab1264', '这是id为2的回答' ) ON conflict ( ID ) DO
UPDATE 
    SET uid = 'postgreOk',
    title = '一次成功了';

如果id为21的存在则实现更新操作,否则实现插入数据, 前提是on conflict ( x)  x在数据中需是唯一约束  

相关文章:

  • 2022-01-01
  • 2022-12-23
  • 2021-06-26
  • 2021-11-01
  • 2022-12-23
  • 2022-02-25
  • 2022-12-23
猜你喜欢
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2021-07-31
  • 2021-11-20
  • 2022-12-23
相关资源
相似解决方案