BUG #18327: Column naming inconsistency for boolean literals in ELSE clauses of CASE expressions.

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: work(dot)michael(dot)2956(at)gmail(dot)com
Subject: BUG #18327: Column naming inconsistency for boolean literals in ELSE clauses of CASE expressions.
Date: 2024-02-03 20:29:56
Message-ID: 18327-f25f77a50d104716@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 18327
Logged by: Michael Bondarenko
Email address: work(dot)michael(dot)2956(at)gmail(dot)com
PostgreSQL version: 14.10
Operating system: MacOS Sonoma 14.1.1 (23B81)
Description:

I'm running my queries on the TPC-H schema, which can be found at:
https://github.com/dimitri/tpch-citus/blob/master/schema/tpch-schema.sql

I found the following inconsistency:

```
tpch=# select case when true then true else true end;
case
------
t
(1 row)

tpch=# select case when true then true else (select true) end;
bool
------
t
(1 row)
```

As you can see, the auto-generated aliases do not correspond. The expected
behaviour was for the first query to also name the column 'bool'.

I base my expectations on:

1) This query naming the result 'bool':
```
tpch=# select true;
bool
------
t
(1 row)
```

2) These queries propagating the column name from the else clause of the
case expression:
2.1) Propagation of the aggregate function name
```
tpch=# select case when true then true else bool_or(true) end;
bool_or
---------
t
(1 row)
```
2.2) Propagation of the [compound] column identifier:
```
tpch=# select case when true then 1 else t1.n_nationkey end from nation as
t1 limit 1;
n_nationkey
-------------
1
(1 row)
```
2.3) Propagation of the simple column identifier:
```
tpch=# select case when true then 1 else n_nationkey end from nation limit
1;
n_nationkey
-------------
1
(1 row)
```
2.4) And even nested case expressions:
```
tpch=# select case when true then 1 else (
case when true then 1 else t1.n_nationkey end
) end from nation as t1 limit 1;
n_nationkey
-------------
1
(1 row)
```

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2024-02-03 22:55:07 BUG #18328: yum update nothing provides libarmadillo.so.12()(64bit) needed by gdal36-libs-3.6.4-6PGDG.rhel9.x86
Previous Message vignesh C 2024-02-03 13:48:19 Re: Potential data loss due to race condition during logical replication slot creation