pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6642: Spanish collation fault
4+ messages / 4 participants
[nested] [flat]

* BUG #6642: Spanish collation fault
@ 2012-05-16 01:45  tulio.carrasco@gmail.com
  0 siblings, 1 reply; 4+ messages in thread

From: tulio.carrasco@gmail.com @ 2012-05-16 01:45 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      6642
Logged by:          T J Carrasco
Email address:      tulio.carrasco@gmail.com
PostgreSQL version: 9.1.3
Operating system:   Ubuntu 12.04 LTS
Description:        

In Spanish every vowel has the same precedence value even with or without
any type of accent, so: a = á = ä = A = Á = Ä

With OS locale = lc_collate = lc_ctype = es_ES.UTF-8 then:

CREATE TABLE test(id integer PRIMARY KEY, dad text, mum text, name text);

INSERT INTO test VALUES (1, 'león','valencia', 'josé'), (2, 'leon',
'mendoza', 'juan'), (3, 'león', 'valárd', 'jose'), (4, 'león','válencia',
'jos'), (5, 'león', 'mendoza', 'jua'), (6, 'leon', 'valencia', 'josie'), (7,
'león', 'valencia', 'josie'), (8, 'leo','zara', 'juan'), (9,
'león','Valencia', 'jos');

SELECT * FROM test order by dad, mum, name; 

We obtain:

id | dad  | mum      | name
---+------+----------+-------
 8 | leo  | zara     | juan
 2 | leon | mendoza  | juan
 6 | leon | valencia | josie
 5 | león | mendoza  | jua
 3 | león | valárd   | jose
 1 | león | valencia | josé
 7 | león | valencia | josie
 9 | león | Valencia | jos
 4 | león | válencia | jos
(9 rows)

Which doesn´t accomplish with Spanish collation. It should be something like
this:

id | dad  | mum      | name
---+------+----------+-------
 8 | leo  | zara     | juan
 2 | leon | mendoza  | juan
 5 | león | mendoza  | jua
 3 | león | valárd   | jose
 4 | león | válencia | jos
 9 | león | Valencia | jos
 1 | león | valencia | josé
 6 | leon | valencia | josie
 7 | león | valencia | josie
(9 rows)

In which due dad column has the same value it uses the mum column and if
they also have the same value then it should use the name column.

Thanks in advance for your help.




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

* Re: BUG #6642: Spanish collation fault
@ 2012-05-16 19:20  Alvaro Herrera <alvherre@commandprompt.com>
  parent: tulio.carrasco@gmail.com
  0 siblings, 1 reply; 4+ messages in thread

From: Alvaro Herrera @ 2012-05-16 19:20 UTC (permalink / raw)
  To: tulio.carrasco <tulio.carrasco@gmail.com>; +Cc: pgsql-bugs


Excerpts from tulio.carrasco's message of mar may 15 21:45:00 -0400 2012:

> In Spanish every vowel has the same precedence value even with or without
> any type of accent, so: a = á = ä = A = Á = Ä

> In which due dad column has the same value it uses the mum column and if
> they also have the same value then it should use the name column.

I see your point, and it makes sense, but it just doesn't work that way.

The way it works is that it goes over the first column and does the two
passes (first ignoring accents, second considering them) over it using
the collating rules you describe; and once that is complete, it goes to
look at the second column.  I don't think it's possible at all to
implement what you suggest, which is to make the first pass over all the
columns and then the second pass over all the columns.

I didn't try, but if you were to do an ORDER BY dad || ' ' || mum ' ' || name
I think it should do what you want.  (Not really sure the spaces are
necessary).  Because then you're sorting on a single string and it can
do the first pass on the whole thing and then the second pass.

-- 
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support



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

* Re: BUG #6642: Spanish collation fault
@ 2012-05-17 00:55  Tulio J Carrasco <tulio.carrasco@gmail.com>
  parent: Alvaro Herrera <alvherre@commandprompt.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Tulio J Carrasco @ 2012-05-17 00:55 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@commandprompt.com>; +Cc: pgsql-bugs

Thank you very much Álvaro,

As far as I understood from someone who knows about ;)  "...the SQL
standard indicates to order according the first column and consider the
second column only for those records which first column has identical order
values..."

The bug I refer to is that first column is FINALLY ordered for character
value -not the order value which the collation requests.

"León", "leon", "leOn" has identical order values: none of them weights
more for Spanish collation and PG is not working according it if PG makes a
"second pass" that ignores collation and reorders by its character value.
Best Regards

Tulio


On Wed, May 16, 2012 at 2:20 PM, Alvaro Herrera
<alvherre@commandprompt.com>wrote:

>
> Excerpts from tulio.carrasco's message of mar may 15 21:45:00 -0400 2012:
>
> > In Spanish every vowel has the same precedence value even with or without
> > any type of accent, so: a = á = ä = A = Á = Ä
>
> > In which due dad column has the same value it uses the mum column and if
> > they also have the same value then it should use the name column.
>
> I see your point, and it makes sense, but it just doesn't work that way.
>
> The way it works is that it goes over the first column and does the two
> passes (first ignoring accents, second considering them) over it using
> the collating rules you describe; and once that is complete, it goes to
> look at the second column.  I don't think it's possible at all to
> implement what you suggest, which is to make the first pass over all the
> columns and then the second pass over all the columns.
>
> I didn't try, but if you were to do an ORDER BY dad || ' ' || mum ' ' ||
> name
> I think it should do what you want.  (Not really sure the spaces are
> necessary).  Because then you're sorting on a single string and it can
> do the first pass on the whole thing and then the second pass.
>
> --
> Álvaro Herrera <alvherre@commandprompt.com>
> The PostgreSQL Company - Command Prompt, Inc.
> PostgreSQL Replication, Consulting, Custom Development, 24x7 support
>

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

* Re: BUG #6642: Spanish collation fault
@ 2012-05-19 23:11  Peter Eisentraut <peter_e@gmx.net>
  parent: Tulio J Carrasco <tulio.carrasco@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Peter Eisentraut @ 2012-05-19 23:11 UTC (permalink / raw)
  To: Tulio J Carrasco <tulio.carrasco@gmail.com>; +Cc: Alvaro Herrera <alvherre@commandprompt.com>; pgsql-bugs

On ons, 2012-05-16 at 19:55 -0500, Tulio J Carrasco wrote:
> "León", "leon", "leOn" has identical order values: none of them
> weights more for Spanish collation and PG is not working according it
> if PG makes a "second pass" that ignores collation and reorders by its
> character value.

PostgreSQL uses the operating system's C library for sorting.  Since you
are using Ubuntu, that is glibc for you.  And a look into the glibc
sources shows that ó is sorted after o, the way Álvaro has explained.
If you disagree with that, you need to take it up with the glibc
maintainers.




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


end of thread, other threads:[~2012-05-19 23:11 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-05-16 01:45 BUG #6642: Spanish collation fault tulio.carrasco@gmail.com
2012-05-16 19:20 ` Alvaro Herrera <alvherre@commandprompt.com>
2012-05-17 00:55   ` Tulio J Carrasco <tulio.carrasco@gmail.com>
2012-05-19 23:11     ` Peter Eisentraut <peter_e@gmx.net>

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