in reply to Re: Postgresql and space characters
in thread Postgresql and space characters

Um, what test?
I was discussing the code I wrote. Yes, yes.. you can rightly complain about my language abilities. I am not even that much better in my native tounge. Here is an sql example of my problem:
create table s ( a varchar(255) ); # ... div inserts ... select a from s order by a; a ---------- fooabba foo bar foo gaa foo gznk fool foonoo foo zazza
Spaces are ignored. That is not possible for my data. (I can live with case not being significant.)
But, there are lots of ways of sorting large perl data structures
I want to use the one built into Perl with maximum speed and support for internationalization. My belief was that Perl's "native" sort would work the same as PostgreSQL, since both seemed to more or less use the native OS implem. Sorry if I was unclear.
Maybe you just need to add an extra column to your table(s), to specify the desired ordering for the data records.
That is in fact the data I am trying to sort. At an absolute minimum, I need a char that I can replace space with -- which will be less than all alphanumeric chars in P-SQL.

MySQL has better sql-support than PostgreSQL(!) here, with different collations on columns, etc. I'll look into that. Pity, I had hoped to support both databases when releasing the code (-: if I ever get so far :-).

Replies are listed 'Best First'.
Re^3: Postgresql and space characters
by graff (Chancellor) on Sep 18, 2006 at 03:52 UTC
    I want to use the one built into Perl with maximum speed and support for internationalization... At an absolute minimum, I need a char that I can replace space with -- which will be less than all alphanumeric chars in P-SQL.

    Now that you've shown an example, it does seem very strange that P-SQL's "order by" behaves like that. If you are using a perl script for both storing to and fetching from P-SQL, you might try replacing spaces with a control character -- e.g. do  tr/ /\x1a/ on the strings before loading the data into the table, and then  tr/\x1a/ / on the strings after you pull them back out from the table.

    But I don't have a P-SQL system available to test this on... maybe it would ignore control characters the same way it ignores spaces. If so, you have to figure out whether you can use something like "/" or "*" or "#" or "%" as a replacement for spaces -- whatever will "stick" during the P-SQL sorting, but is not already present in the original data.

    Is there too much of this data to be held in memory at one time? If the perl script that loads the table has all the data in one array or whatever, you could create your table like this:

    create table s ( a varchar(255), o int ); # insert the string and its numeric sort order as set by perl's sort select a from s order by o;
      maybe it would ignore control characters the same way it ignores spaces.
      I did try a few control chars, but none of them worked.

      I would want it to work whatever language system was used to initdb PostgreSQL. I.e., if a control char is ignored in some language system, my program won't work. :-(

      I'm surprised -- half the people on Perlmonks should have been bitten by this?! I checked a lot before asking because I expected an embarrassingly obvious faq reference. (-: 1/2 Everyone use MySQL?! 1/2 :-)

      Is there too much of this data to be held in memory at one time?
      Oh yes. :-)

      (I am really trying to store relations among persistent objects. I use the db for the persistence anyway.)

      Ah well, time to port to MySQL. Thanks for help!