【问题标题】:How to convert mysql if condition based value insertion to postgresql如果基于条件的值插入如何将mysql转换为postgresql
【发布时间】:2021-02-12 04:37:25
【问题描述】:
insert into agreement_form 
  set created = now(), 
      market_fk = (if (? = '''', null, (select m.id from market m where m.name = ?)))

上面的查询是根据参数值插入 market_fk 的值,它在 MySQL 中工作。上面的查询如何转成postgresql?

【问题讨论】:

    标签: mysql postgresql insert conditional-statements


    【解决方案1】:

    使用insert ... select

    insert into agreement_form (created, market_fk)
    select now(), 
           case  
              when ? = '''' then null
              else (select m.id from market m where m.name = ?)
           end;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-10
      • 2021-10-30
      • 2020-09-13
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      • 2015-09-16
      相关资源
      最近更新 更多