Re: BUG #18690: A count function returns wrong value when using FDW

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: aidar(at)donorbox(dot)org, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18690: A count function returns wrong value when using FDW
Date: 2024-11-06 11:03:44
Message-ID: CAApHDvoMwifCTZ6SgokRH49R-3MK5WYzBb+cwjvwb=RKpJOATw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, 6 Nov 2024 at 22:58, PG Bug reporting form
<noreply(at)postgresql(dot)org> wrote:
> ```
> WITH
>
> transactions AS ( SELECT * FROM transactions_fwd WHERE org_id = 1
> ),
> recurring_payments AS ( SELECT * FROM recurring_payments_fwd WHERE
> org_id = 1 )
> SELECT AVG(t.usd_amount_cents / 100) AS average_donation_usd
> FROM transactions t
> JOIN recurring_payments r ON r.id = t.recurring_payment_id
> WHERE t.status = 'paid' AND t.deleted_at IS NULL AND t.amount_refunded_cents
> = 0
> ```
>
> But when I wrap it to `select count(*) from (my_query)` i get 288 as a
> result, but I expect it to be 1.
>
> ```
> select count(*)
> FROM (
> WITH
>
> transactions AS ( SELECT * FROM transactions_fwd WHERE org_id = 1
> ),
> recurring_payments AS ( SELECT * FROM recurring_payments_fwd WHERE
> org_id = 1 )
> SELECT AVG(t.usd_amount_cents / 100) AS average_donation_usd
> FROM transactions t
> JOIN recurring_payments r ON r.id = t.recurring_payment_id
> WHERE t.status = 'paid' AND t.deleted_at IS NULL AND t.amount_refunded_cents
> = 0
> );
> ```

Can you show the EXPLAIN ANALYZE of both of these queries?

Also, can you work on getting a self-contained reproducer that we can
run to recreate the issue.

David

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2024-11-06 11:59:48 BUG #18691: Turkish Character Encoding
Previous Message Amit Kapila 2024-11-06 10:32:46 Re: BUG #18683: A publication must be created *before* a logical rep slot in order to be used with that slot?