【问题标题】:Variables in PostgreSql (pgAdmnin query)PostgreSql 中的变量(pgAdminin 查询)
【发布时间】:2014-11-04 02:57:56
【问题描述】:

我有一个问题           

delete from qdocs where path < './qbin/arch/2014-08-01' + and path > './qbin/arch'

需要像变量一样

delete from qdocs where path < './qbin/arch/current_date - 31 day' + and path > './qbin/arch'

【问题讨论】:

    标签: postgresql variables


    【解决方案1】:

    您可以使用date/time functions,如下所示:

    delete from qdocs where path < './qbin/arch/' || current_date - 31 and path > './qbin/arch'
    

    还有更多可能的修改日期的方法:

    select current_date - integer '31';
    select (current_date - interval '31 days')::date;
    select (current_date - interval '1 month')::date;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      • 2010-12-02
      • 2017-11-21
      • 1970-01-01
      相关资源
      最近更新 更多