Case in Order By Ignored without warning or error - Mailing list pgsql-bugs

From Emiel Hermsen
Subject Case in Order By Ignored without warning or error
Date
Msg-id CABBJNBuLrK2giyL9tmauipdRHZsMoOpDs3cJcnCUUdWJGj6ftw@mail.gmail.com
Whole thread Raw
Responses Re: Case in Order By Ignored without warning or error  (Francisco Olarte <folarte@peoplecall.com>)
List pgsql-bugs
Hello,

I'm currently working with PostGreSQL 9.3 on a RedHat 6.6 device.
One of my predecessors decided he wanted dynamic sorting which seems to be
ignored.

My made-up testing table definition is as follows:
CREATE TABLE films (
    id        SERIAL PRIMARY KEY,
    title       varchar(40) NOT NULL,
     imdbnumber     integer
);

INSERT INTO films (title, imdbnumber) VALUES ('Film a', 2000), ('Film b',
1999);

When using psql on the command line, I enter the following query:

select * from films order by (case 1 when 1 then 3 else 1 end);

I would expect this query to either sort on column 3, or refuse with an
error.
Instead it executes the query with incorrect sorting and no warning or
error.

Also when using indexes that are out of bounds, like -2 or 8, there are
neither warnings/errors nor sorting.

According to documentation,
https://www.postgresql.org/docs/9.3/static/queries-order.html, my select
query above is incorrect, however psql does not tell me this.

I don't see it as a problem, now that I know what PostGreSQL does, but I
would assume others without this knowledge would prefer at least a warning
or even an error.

Kind Regards,

Emiel Hermsen

pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BUG #14179: Not enough info in error message
Next
From: Francisco Olarte
Date:
Subject: Re: Case in Order By Ignored without warning or error