【问题标题】:Running query from scratch with something like exec function?使用 exec 函数从头开始运行查询?
【发布时间】:2011-01-27 21:56:20
【问题描述】:

是否可以在不使用函数的情况下使用 Postgresql 制作类似于以下内容的内容?

伪sql代码:

select * from sometable where somecol = somevalue AND someothercol IN exec('select something from excludelist')

我的主要目的是建立一个带有预定义查询的表,以便在 where 子句中调用

伪sql代码: select * from sometable where somecol = somevalue AND someothercol IN exec( 从预定义查询中选择查询,其中 id=someid )

【问题讨论】:

    标签: postgresql


    【解决方案1】:

    据我所知,唯一的选择是:

    prepare my_usr_id as select usr_id from usr where usr_id < $1;
    create temp table my_temp on commit drop as execute my_usr_id(10);
    select * from usr join my_temp using (usr_id);
    

    【讨论】:

    • 谢谢你,真的是一个很好的建议,甚至比我在我的问题中想出的还要多
    猜你喜欢
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 2014-11-28
    • 1970-01-01
    • 2021-11-27
    • 2019-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多