pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
sort order
10+ messages / 5 participants
[nested] [flat]

* sort order
@ 2011-12-11 16:17 Abraham, Danny <danny_abraham@bmc.com>
  2011-12-12 15:52 ` Re: sort order Adrian Klaver <adrian.klaver@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Abraham, Danny @ 2011-12-11 16:17 UTC (permalink / raw)
  To: pgsql-general; +Cc: Abraham, Danny <danny_abraham@bmc.com>

On PG 9.0.4, Windows, Encoding and Collate WIN1252  trying to get a database to sort according to the ascii order.
Example:
Select t from test order by t
Should be exactly like
Select t from test order by ascii(t).

Can it be done? How?

Thanks

Danny

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: sort order
  2011-12-11 16:17 sort order Abraham, Danny <danny_abraham@bmc.com>
@ 2011-12-12 15:52 ` Adrian Klaver <adrian.klaver@gmail.com>
  2011-12-12 15:55   ` Re: sort order Abraham, Danny <danny_abraham@bmc.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Adrian Klaver @ 2011-12-12 15:52 UTC (permalink / raw)
  To: pgsql-general; +Cc: Abraham, Danny <danny_abraham@bmc.com>

On Sunday, December 11, 2011 8:17:41 am Abraham, Danny wrote:
> On PG 9.0.4, Windows, Encoding and Collate WIN1252  trying to get a
> database to sort according to the ascii order. Example:
> Select t from test order by t
> Should be exactly like
> Select t from test order by ascii(t).
> 
> Can it be done? How?

Not after a database has been created.

For more info see:
http://www.postgresql.org/docs/9.0/interactive/locale.html
In particular LC_COLLATE.

> 
> Thanks
> 
> Danny

-- 
Adrian Klaver
adrian.klaver@gmail.com



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: sort order
  2011-12-11 16:17 sort order Abraham, Danny <danny_abraham@bmc.com>
  2011-12-12 15:52 ` Re: sort order Adrian Klaver <adrian.klaver@gmail.com>
@ 2011-12-12 15:55   ` Abraham, Danny <danny_abraham@bmc.com>
  2011-12-12 16:07     ` Re: sort order Tom Lane <tgl@sss.pgh.pa.us>
  2011-12-12 16:09     ` Re: sort order Adrian Klaver <adrian.klaver@gmail.com>
  0 siblings, 2 replies; 10+ messages in thread

From: Abraham, Danny @ 2011-12-12 15:55 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@gmail.com>; pgsql-general; +Cc: Abraham, Danny <danny_abraham@bmc.com>

This is exactly what I am trying to do -
To find a CREATE DATABASE statement that will produce a database that has a binary sorting.

Thanks

Danny

-----Original Message-----
From: Adrian Klaver [mailto:adrian.klaver@gmail.com] 
Sent: Monday, December 12, 2011 5:53 PM
To: pgsql-general@postgresql.org
Cc: Abraham, Danny
Subject: Re: [GENERAL] sort order

On Sunday, December 11, 2011 8:17:41 am Abraham, Danny wrote:
> On PG 9.0.4, Windows, Encoding and Collate WIN1252  trying to get a
> database to sort according to the ascii order. Example:
> Select t from test order by t
> Should be exactly like
> Select t from test order by ascii(t).
> 
> Can it be done? How?

Not after a database has been created.

For more info see:
http://www.postgresql.org/docs/9.0/interactive/locale.html
In particular LC_COLLATE.

> 
> Thanks
> 
> Danny

-- 
Adrian Klaver
adrian.klaver@gmail.com




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: sort order
  2011-12-11 16:17 sort order Abraham, Danny <danny_abraham@bmc.com>
  2011-12-12 15:52 ` Re: sort order Adrian Klaver <adrian.klaver@gmail.com>
  2011-12-12 15:55   ` Re: sort order Abraham, Danny <danny_abraham@bmc.com>
@ 2011-12-12 16:07     ` Tom Lane <tgl@sss.pgh.pa.us>
  2011-12-12 16:16       ` Re: sort order Abraham, Danny <danny_abraham@bmc.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Tom Lane @ 2011-12-12 16:07 UTC (permalink / raw)
  To: Abraham, Danny <danny_abraham@bmc.com>; +Cc: Adrian Klaver <adrian.klaver@gmail.com>; pgsql-general

"Abraham, Danny" <danny_abraham@bmc.com> writes:
> This is exactly what I am trying to do -
> To find a CREATE DATABASE statement that will produce a database that has a binary sorting.

Setting its LC_COLLATE to "C" ought to do that.

BTW, as of 9.1 you can control this at finer granularity than database
level, see the COLLATE clause.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: sort order
  2011-12-11 16:17 sort order Abraham, Danny <danny_abraham@bmc.com>
  2011-12-12 15:52 ` Re: sort order Adrian Klaver <adrian.klaver@gmail.com>
  2011-12-12 15:55   ` Re: sort order Abraham, Danny <danny_abraham@bmc.com>
  2011-12-12 16:07     ` Re: sort order Tom Lane <tgl@sss.pgh.pa.us>
@ 2011-12-12 16:16       ` Abraham, Danny <danny_abraham@bmc.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Abraham, Danny @ 2011-12-12 16:16 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Adrian Klaver <adrian.klaver@gmail.com>; pgsql-general

Thanks a lot.

Worked fine with .....  

CREATE DATABASE danny
Template template0
LC_CTYPE = 'C'
LC_COLLATE = 'C';

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us] 
Sent: Monday, December 12, 2011 6:07 PM
To: Abraham, Danny
Cc: Adrian Klaver; pgsql-general@postgresql.org
Subject: Re: [GENERAL] sort order 

"Abraham, Danny" <danny_abraham@bmc.com> writes:
> This is exactly what I am trying to do -
> To find a CREATE DATABASE statement that will produce a database that has a binary sorting.

Setting its LC_COLLATE to "C" ought to do that.

BTW, as of 9.1 you can control this at finer granularity than database
level, see the COLLATE clause.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: sort order
  2011-12-11 16:17 sort order Abraham, Danny <danny_abraham@bmc.com>
  2011-12-12 15:52 ` Re: sort order Adrian Klaver <adrian.klaver@gmail.com>
  2011-12-12 15:55   ` Re: sort order Abraham, Danny <danny_abraham@bmc.com>
@ 2011-12-12 16:09     ` Adrian Klaver <adrian.klaver@gmail.com>
  1 sibling, 0 replies; 10+ messages in thread

From: Adrian Klaver @ 2011-12-12 16:09 UTC (permalink / raw)
  To: Abraham, Danny <danny_abraham@bmc.com>; +Cc: pgsql-general

On Monday, December 12, 2011 7:55:37 am Abraham, Danny wrote:
> This is exactly what I am trying to do -
> To find a CREATE DATABASE statement that will produce a database that has a
> binary sorting.

http://www.postgresql.org/docs/9.0/interactive/sql-createdatabase.html
CREATE DATABASE name
    [ [ WITH ] [ OWNER [=] user_name ]
           [ TEMPLATE [=] template ]
           [ ENCODING [=] encoding ]
           [ LC_COLLATE [=] lc_collate ]
           [ LC_CTYPE [=] lc_ctype ]
           [ TABLESPACE [=] tablespace ]
           [ CONNECTION LIMIT [=] connlimit ] ]

Be sure and read the Notes section at the bottom for important caveats.

> 
> Thanks


-- 
Adrian Klaver
adrian.klaver@gmail.com



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* sort order
@ 2021-07-27 17:07 Marc Millas <marc.millas@mokadb.com>
  2021-07-27 17:29 ` Re: sort order Marc Millas <marc.millas@mokadb.com>
  2021-08-06 15:57 ` Re: sort order Peter Eisentraut <peter.eisentraut@enterprisedb.com>
  0 siblings, 2 replies; 10+ messages in thread

From: Marc Millas @ 2021-07-27 17:07 UTC (permalink / raw)
  To: pgsql-general

Hi,

context:
one postgres 12 on centos 7
one postgres 12 on windows 10
both on machines with french as default
the centos 7 lc_collate and lc_ctype: fr_FR.UTF_8
the w10 lc_collate and lc_ctype: French_France.1252


create table test (ble text, id serial primary key);
insert into test(ble) values(' ');
insert into test(ble) values('Marc');
insert into test(ble) values(' Marc');
insert into test(ble) values('marc');
insert into test(ble) values(' marc');
insert into test(ble) values('bobo');
insert into test(ble) values(' bobo'):
insert into test(ble) values('élise');

differences include a french é character, and some white spaces at the
beginning.

then select * from test order by ble;

centos result:
  ble  | id
-------+----
       |  3
 bobo  |  2
  bobo |  1
 élise |  6
 marc  |  5
  marc |  4
 Marc  |  8
  Marc |  7
(8 lignes)

w10 result:
  ble  | id
-------+----
       |  3
  bobo |  1
  marc |  4
  Marc |  7
 élise |  8
 bobo  |  2
 marc  |  5
 Marc  |  6
(8 lignes)

so, obviously, both lc_collate knows about the é
but obviously, too, they do behave differently on the impact of the
beginning white space.

I didn't see anything about this behaviour on the doc, unless the reference
at the libc should be understood as please read and test libc doc on each
platform.
So my first question is: why ?
My second question is: how to make the centos postgres behave like the w10
one ??
ie. knowing about french characters AND taking beginning white spaces into
account ?

thanks,

regards,


Marc MILLAS
Senior Architect
+33607850334
www.mokadb.com

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: sort order
  2021-07-27 17:07 sort order Marc Millas <marc.millas@mokadb.com>
@ 2021-07-27 17:29 ` Marc Millas <marc.millas@mokadb.com>
  2021-07-27 17:40   ` Re: sort order Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 10+ messages in thread

From: Marc Millas @ 2021-07-27 17:29 UTC (permalink / raw)
  To: pgsql-general

Re-reading my post, I see that even the élise is not sorted correctly on
w10...

Marc MILLAS
Senior Architect
+33607850334
www.mokadb.com



On Tue, Jul 27, 2021 at 7:07 PM Marc Millas <marc.millas@mokadb.com> wrote:

> Hi,
>
> context:
> one postgres 12 on centos 7
> one postgres 12 on windows 10
> both on machines with french as default
> the centos 7 lc_collate and lc_ctype: fr_FR.UTF_8
> the w10 lc_collate and lc_ctype: French_France.1252
>
>
> create table test (ble text, id serial primary key);
> insert into test(ble) values(' ');
> insert into test(ble) values('Marc');
> insert into test(ble) values(' Marc');
> insert into test(ble) values('marc');
> insert into test(ble) values(' marc');
> insert into test(ble) values('bobo');
> insert into test(ble) values(' bobo'):
> insert into test(ble) values('élise');
>
> differences include a french é character, and some white spaces at the
> beginning.
>
> then select * from test order by ble;
>
> centos result:
>   ble  | id
> -------+----
>        |  3
>  bobo  |  2
>   bobo |  1
>  élise |  6
>  marc  |  5
>   marc |  4
>  Marc  |  8
>   Marc |  7
> (8 lignes)
>
> w10 result:
>   ble  | id
> -------+----
>        |  3
>   bobo |  1
>   marc |  4
>   Marc |  7
>  élise |  8
>  bobo  |  2
>  marc  |  5
>  Marc  |  6
> (8 lignes)
>
> so, obviously, both lc_collate knows about the é
> but obviously, too, they do behave differently on the impact of the
> beginning white space.
>
> I didn't see anything about this behaviour on the doc, unless the
> reference at the libc should be understood as please read and test libc doc
> on each platform.
> So my first question is: why ?
> My second question is: how to make the centos postgres behave like the w10
> one ??
> ie. knowing about french characters AND taking beginning white spaces into
> account ?
>
> thanks,
>
> regards,
>
>
> Marc MILLAS
> Senior Architect
> +33607850334
> www.mokadb.com
>
>

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: sort order
  2021-07-27 17:07 sort order Marc Millas <marc.millas@mokadb.com>
  2021-07-27 17:29 ` Re: sort order Marc Millas <marc.millas@mokadb.com>
@ 2021-07-27 17:40   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 10+ messages in thread

From: Tom Lane @ 2021-07-27 17:40 UTC (permalink / raw)
  To: Marc Millas <marc.millas@mokadb.com>; +Cc: pgsql-general

Marc Millas <marc.millas@mokadb.com> writes:
> Re-reading my post, I see that even the élise is not sorted correctly on
> w10...

Sort orders aren't even particularly guaranteed on different releases
of the same platform, let alone totally different platforms.  glibc
made major changes to their collation rules not long ago:

https://wiki.postgresql.org/wiki/Locale_data_changes

At one time we thought that migrating to ICU sorting might bring
a little more stability to this, but I think what we've found so
far is that it's just different :-(

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: sort order
  2021-07-27 17:07 sort order Marc Millas <marc.millas@mokadb.com>
@ 2021-08-06 15:57 ` Peter Eisentraut <peter.eisentraut@enterprisedb.com>
  1 sibling, 0 replies; 10+ messages in thread

From: Peter Eisentraut @ 2021-08-06 15:57 UTC (permalink / raw)
  To: Marc Millas <marc.millas@mokadb.com>; pgsql-general

On 27.07.21 19:07, Marc Millas wrote:
> so, obviously, both lc_collate knows about the é
> but obviously, too, they do behave differently on the impact of the 
> beginning white space.
> 
> I didn't see anything about this behaviour on the doc, unless the 
> reference at the libc should be understood as please read and test libc 
> doc on each platform.
> So my first question is: why ?
> My second question is: how to make the centos postgres behave like the 
> w10 one ??
> ie. knowing about french characters AND taking beginning white spaces 
> into account ?

There are multiple standard ways to deal with space and punctuation 
characters when sorting.  See 
<https://unicode-org.github.io/icu/userguide/collation/customization/ignorepunct.html; 
for a description.  Not all collation providers implement all of them, 
but the behavior you happen to get is usually one of them.  The centos 7 
behavior corresponds to "shift-trimmed", the Windows one appears to 
match "non-ignorable".  If you want to get that latter one on Linux as 
well, you can use the ICU locales, which also default to non-ignorable. 
For example

     select * from test order by ble collate "fr-x-icu";

matches your Windows output for me.





^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2021-08-06 15:57 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-12-11 16:17 sort order Abraham, Danny <danny_abraham@bmc.com>
2011-12-12 15:52 ` Adrian Klaver <adrian.klaver@gmail.com>
2011-12-12 15:55   ` Abraham, Danny <danny_abraham@bmc.com>
2011-12-12 16:07     ` Tom Lane <tgl@sss.pgh.pa.us>
2011-12-12 16:16       ` Abraham, Danny <danny_abraham@bmc.com>
2011-12-12 16:09     ` Adrian Klaver <adrian.klaver@gmail.com>
2021-07-27 17:07 sort order Marc Millas <marc.millas@mokadb.com>
2021-07-27 17:29 ` Marc Millas <marc.millas@mokadb.com>
2021-07-27 17:40   ` Tom Lane <tgl@sss.pgh.pa.us>
2021-08-06 15:57 ` Peter Eisentraut <peter.eisentraut@enterprisedb.com>

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