pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: work.michael.2956@gmail.com
Subject: BUG #18327: Column naming inconsistency for boolean literals in ELSE clauses of CASE expressions.
Date: Sat, 03 Feb 2024 20:29:56 +0000
Message-ID: <18327-f25f77a50d104716@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      18327
Logged by:          Michael Bondarenko
Email address:      work.michael.2956@gmail.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)
```



view thread (3+ messages)  latest in thread

Message-ID: <18327-f25f77a50d104716@postgresql.org>
Permalink:  ../18327-f25f77a50d104716@postgresql.org/
Also on:    postgresql.org/message-id/18327-f25f77a50d104716@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, work.michael.2956@gmail.com
  Subject: Re: BUG #18327: Column naming inconsistency for boolean literals in ELSE clauses of CASE expressions.
  In-Reply-To: <18327-f25f77a50d104716@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox