BUG #17150: Unexpected outputs from the query - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #17150: Unexpected outputs from the query
Date
Msg-id 17150-d22e14860d93d32e@postgresql.org
Whole thread Raw
Responses Re: BUG #17150: Unexpected outputs from the query  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      17150
Logged by:          Yu Liang
Email address:      luy70@psu.edu
PostgreSQL version: 14beta3
Operating system:   Ubuntu 20.04 LTS
Description:

For query 

```SQL
CREATE TABLE v0 ( v1 INT );
CREATE VIEW v2 AS SELECT * FROM v0 WHERE v1 = 0;

SELECT SUM(result) FROM ( SELECT ALL( true )::INT as result FROM v2 ORDER BY
( SELECT COUNT ( v1  )  ) ) as res; 
-- Expected sum = "0", returns sum = "1"
```

Detailed outputs: 
```
     1: sum    (typeid = 20, len = 8, typmod = -1, byval = t)
    ----
     1: sum = "1"    (typeid = 20, len = 8, typmod = -1, byval = t)
    ----
```

In the query above, given TABLE v0 has no data inserted, and v2 is a view
that observes on v0, we expect the SELECT statement that tries to sum up the
entries of v2 would output sum = "0". However, sum = "1" is returned. This
unexpected return can be fixed by removing "ORDER BY ( SELECT COUNT ( v1  )
)", then the query returns sum="0" as expected. 

This behavior can be reproduced with an empty database, using Postgres
single mode.  Postgres version = "PostgreSQL 14beta3 on x86_64-pc-linux-gnu,
compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit".


pgsql-bugs by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: BUG #17148: About --no-strict-names option and --quiet option of pg_amcheck command
Next
From: "Euler Taveira"
Date:
Subject: Re: BUG #17148: About --no-strict-names option and --quiet option of pg_amcheck command