Thread: Ordering a name list and ignoring whitespace
Hi all, Doing some googling and looking through the docs, I can't find an obvious way to do this beside post processing after the query (which I am trying to avoid). I'm trying to select a list of names in alphabetical order but ignoring the whitespace. So for example, the name "La Combe" should come after "Lace" but before "Lacs..." Any ideas? Mikel
Mikel Lindsaar wrote: > Hi all, > > Doing some googling and looking through the docs, I can't find an > obvious way to do this beside post processing after the query (which I > am trying to avoid). > > I'm trying to select a list of names in alphabetical order but > ignoring the whitespace. > > So for example, the name "La Combe" should come after "Lace" but > before "Lacs..." > > Any ideas? Could you do it like this: SELECT replace(name_column, ' ', '') AS name_replaced FROM your_table_name ORDER BY name_replaced This can get a bit slowish if your table has quite a number of rows. Mike
Mikel Lindsaar <raasdnil@gmail.com> writes: > I'm trying to select a list of names in alphabetical order but > ignoring the whitespace. > So for example, the name "La Combe" should come after "Lace" but > before "Lacs..." FWIW, this would probably happen automatically if you were using a non-C locale. I'm not sure that's really a good solution, because switching to a different locale would affect every sort operation you ever do. But it's an alternative to consider. regards, tom lane