I want to sort data in a PostgreSQL table in the same way as in large Perl data structures. (To cache large data structures transparently in the db)

I read about i18n settings (initdb for P-sql, etc) and it looked easy. show all; in psql shows lc_collate eq en_US.UTF-8.

It doesn't even work for 7-bit ASCII strings! PostgreSQL ignores case and spaces (in strings -- not only postfix?!). Spaces inside strings are needed in some cases, so I can't just repack everything.

I saw that the "C" locale should sort on spaces, but then it won't sort i18n char sets correctly.

I use the standard Ubuntu P-SQL and Perl for this simple test.

A common sorting problem like this should either be very simple or discussed in lots of places. Since I can't seem to find those discussions, I'm missing something obvious? :-)

Update: Fixed language after I slept. :-)

Update 2: Ported to MySQL 5 and Collation works well, even supports case sensitivity (if I want it). My tests also run noticeably faster (with InnoDB). PostgreSQL seems behind MySQL in sql standard support in this area.


In reply to Postgresql and space characters by BerntB

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.