Re: [SQL] ORDER BY CASE ...

2006-02-20 Thread Bruno Wolff III
On Mon, Feb 13, 2006 at 22:28:38 +0100, Mario Splivalo <[EMAIL PROTECTED]> wrote: > Can't do so, because receiving_time is timestamptz, and "from" is > varchar. There: > > pulitzer2=# select id, "from", receiving_time from messages order by > case when 2=3 then "from" else receiving_time end des

Re: [SQL] ORDER BY CASE ...

2006-02-13 Thread Mario Splivalo
On Mon, 2006-02-13 at 17:10 +0100, Mathieu Arnold wrote: > | It works like this: > | > | ORDER BY (CASE WHEN 5=5 THEN "from"::varchar ELSE > | receiving_time::varchar) DESC. > | > | Is there a way to have DESC/ASC inside of a CASE? > | > | Mario > > No, you don't understand, you should do s

Re: [SQL] ORDER BY CASE ...

2006-02-13 Thread Mathieu Arnold
+-le 13/02/2006 16:47 +0100, Mario Splivalo a dit : | On Mon, 2006-02-13 at 16:39 +0100, Mathieu Arnold wrote: |> | |> | I tought I'd get differently sorted data, since in the first query I |> | said 5=5, and in second I said 5=6. |> |> Well, no, in the first, the result of the CASE is 2, and in

Re: [SQL] ORDER BY CASE ...

2006-02-13 Thread Reinoud van Leeuwen
On Mon, Feb 13, 2006 at 04:35:30PM +0100, Mario Splivalo wrote: > Am I misusing the ORDER BY with CASE, or, what? :) > > I have a table, messages, half dozen of columns, exposing here just > three of them: > > pulitzer2=# select id, "from", receiving_time from messages where > service_id = 20 ord

Re: [SQL] ORDER BY CASE ...

2006-02-13 Thread Mario Splivalo
On Mon, 2006-02-13 at 16:39 +0100, Mathieu Arnold wrote: > | > | > | I tought I'd get differently sorted data, since in the first query I > | said 5=5, and in second I said 5=6. > > Well, no, in the first, the result of the CASE is 2, and in the second 3, it > means that for every line, it'll

Re: [SQL] ORDER BY CASE ...

2006-02-13 Thread Mathieu Arnold
+-le 13/02/2006 16:35 +0100, Mario Splivalo a dit : | Am I misusing the ORDER BY with CASE, or, what? :) | | I have a table, messages, half dozen of columns, exposing here just | three of them: | | pulitzer2=# select id, "from", receiving_time from messages where | service_id = 20 order by case

[SQL] ORDER BY CASE ...

2006-02-13 Thread Mario Splivalo
Am I misusing the ORDER BY with CASE, or, what? :) I have a table, messages, half dozen of columns, exposing here just three of them: pulitzer2=# select id, "from", receiving_time from messages where service_id = 20 order by case when 5=5 then 2 else 3 end desc limit 5; id | from |

Re: [SQL] ORDER BY case insensitive?

2001-10-05 Thread Bob Swerdlow
need to uppercase all of the data before adding to the table? (yuk) - Bob - Original Message - From: "Jason Earl" <[EMAIL PROTECTED]> To: "Bob Swerdlow" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Thursday, October 04, 2001 3:47 PM Subject: Re:

Re: [SQL] ORDER BY case insensitive?

2001-10-04 Thread Tom Lane
Keith Gray <[EMAIL PROTECTED]> writes: > How would PostgreSQL know to use the index > MyTable_lower_idx when I do a ... > SELECT * FROM MyTable WHERE lower(name) LIKE 'jas%'; The same way it knows to use any other index: it matches up the things mentioned in the WHERE clause with the available i

Re: [SQL] ORDER BY case insensitive?

2001-10-04 Thread Keith Gray
Jason Earl wrote: > > You can, however, create an index like: > > create index MyTable_lower_idx on MyTable > (lower(name)); > > It won't help with your particular query, but it > certainly would help for queries like: > > SELECT * FROM MyTable WHERE lower(name) = 'jason'; > How would Postgr

Re: [SQL] ORDER BY case insensitive?

2001-10-04 Thread Stephan Szabo
On Thu, 4 Oct 2001, Jason Earl wrote: > My guess is that compared to the task of sorting > millions of names the fact that you have to lowercase > them first is not going to be a particular burden. No > matter what you do you are going to get a table scan > (unless you qualify your select with a

Re: [SQL] ORDER BY case insensitive?

2001-10-04 Thread Jason Earl
e this efficient, do we need to uppercase all > of the data before > adding to the table? (yuk) > > - Bob > > > - Original Message - > From: "Jason Earl" <[EMAIL PROTECTED]> > To: "Bob Swerdlow" <[EMAIL PROTECTED]>; > <[E

Re: [SQL] ORDER BY case insensitive?

2001-10-04 Thread Jason Earl
SELECT * FROM MyTable ORDER BY lower(Name); Should do the trick. Jason Earl --- Bob Swerdlow <[EMAIL PROTECTED]> wrote: > How do I get the rows sorted in a case insensitive > way? > > I have some queries that basically fit the form: > SELECT * FROM MyTable ORDER BY Name; > When I view the

[SQL] ORDER BY case insensitive?

2001-10-04 Thread Bob Swerdlow
How do I get the rows sorted in a case insensitive way? I have some queries that basically fit the form: SELECT * FROM MyTable ORDER BY Name; When I view the results, all of the Name's that start with an upper case letter precede all of the Name's that start with a lower case letter. I want

Re: [SQL] ORDER BY case insensitive?

2001-10-03 Thread Jeff Boes
In article , "Bob Swerdlow" <[EMAIL PROTECTED]> wrote: > How do I get the rows sorted in a case insensitive way? > SELECT * FROM MyTable ORDER BY Name; Try SELECT * FROM MyTable ORDER BY upper(Name); (or 'lower(Name)'). -- Jeff Boes