BUG #17168: Incorrect sorting

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: alfonsovicente(at)gmail(dot)com
Subject: BUG #17168: Incorrect sorting
Date: 2021-08-30 17:50:18
Message-ID: 17168-ba6f8f2c7dab4282@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: 17168
Logged by: Alfonso Vicente
Email address: alfonsovicente(at)gmail(dot)com
PostgreSQL version: 13.2
Operating system: Red Hat Enterprise Linux 8
Description:

This is a minimal example to reproduce the error, the "ara" tuple is
incorrectly sorted between "a r" and "a s"

test=> with s1 as (select 'a r' c), s2 as (select 'ara' c), s3 as (select 'a
s' c) select c from (select c from s1 union all select c from s2 union all
select c from s3) as foo order by 1;
c
-----
a r
ara
a s
(3 rows)

It appears to be related with spaces, here are two examples that shows the
same problem with the "ara" and "aja" strings

Example 1
------------------

test=> with s1 as (select 'a r' c), s2 as (select 'ara' c), s3 as (select 'a
q' c) select c from (select c from s1 union all select c from s2 union all
select c from s3) as foo order by 1;
c
-----
a q
a r
ara
(3 rows)

test=> with s1 as (select 'a r' c), s2 as (select 'ara' c), s3 as (select 'a
r' c) select c from (select c from s1 union all select c from s2 union all
select c from s3) as foo order by 1;
c
-----
a r
a r
ara
(3 rows)

test=> with s1 as (select 'a r' c), s2 as (select 'ara' c), s3 as (select 'a
s' c) select c from (select c from s1 union all select c from s2 union all
select c from s3) as foo order by 1;
c
-----
a r
ara
a s
(3 rows)

Example 2
------------------

test=> with s1 as (select 'a j' c), s2 as (select 'aja' c), s3 as (select 'a
i' c) select c from (select c from s1 union all select c from s2 union all
select c from s3) as foo order by 1;
c
-----
a i
a j
aja
(3 rows)

test=> with s1 as (select 'a j' c), s2 as (select 'aja' c), s3 as (select 'a
j' c) select c from (select c from s1 union all select c from s2 union all
select c from s3) as foo order by 1;
c
-----
a j
a j
aja
(3 rows)

test=> with s1 as (select 'a j' c), s2 as (select 'aja' c), s3 as (select 'a
k' c) select c from (select c from s1 union all select c from s2 union all
select c from s3) as foo order by 1;
c
-----
a j
aja
a k
(3 rows)

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2021-08-30 18:05:49 Re: Postgres bug report
Previous Message Jeremy Spray 2021-08-30 17:20:34 Postgres bug report