Does pg promise support WITH clause in query file?

162 views Asked by At

If I put this in one query file how will pg promise handle it?

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;

Is there a need to use WITH at all? I want to have the following use case,

SELECT * FROM balance WHERE bank_id = 1 FOR UPDATE (force all bank id 1 record to be locked)

SELECT * FROM balance WHERE bank_id = 1 AND amount = 500 (just get rows with bank id 1, but still making sure all bank id records 1 are locked`

1

There are 1 answers

2
vitaly-t On

pg-promise doesn't care what your SQL is made of, simply sending it into the server as is.

...which makes your question irrelevant/invalid.