pg是否在查询文件中承诺支持WITH子句?

时间:2017-09-13 04:29:17

标签: pg-promise

如果我把它放在一个查询文件中,pg promise将如何处理它?<​​/ p>

WITH regional_sales AS (
        SELECT region, SUM(amount) AS total_sales
        FROM orders
        GROUP BY region
     ), top_regions AS (
        SELECT region
        FROM regional_sales
        WHERE total_sales > (SELECT SUM(total_sales)/10 FROM regional_sales)
     )
SELECT region,
       product,
       SUM(quantity) AS product_units,
       SUM(amount) AS product_sales
FROM orders
WHERE region IN (SELECT region FROM top_regions)
GROUP BY region, product;

是否需要使用WITH?我想有以下用例,

SELECT * FROM balance WHERE bank_id = 1 FOR UPDATE(强制所有银行ID 1记录被锁定)

SELECT * FROM balance WHERE bank_id = 1 AND amount = 500(只获取银行ID为1的行,但仍确保所有银行ID记录1都被锁定。

1 个答案:

答案 0 :(得分:0)

pg-promise并不关心您的SQL是什么,只需将其按原样发送到服务器。

...这使您的问题无关紧要/无效。