Terry Brick <[EMAIL PROTECTED]> writes:
> I'm porting a bunch of queries from MySQL to Postgres 7.4 and am having a problem
> with one
> particular area. For example, a query like this works in MySQL:
> select
> to_char(myCol,'Mon YY')
> from
> myTable
> group by
> to_char(myCol,'MM YYYY')
> order by
> to_char(myCol,'MM YYYY')
Ah, good ol' MySQL :-( ... let the user do what he wants whether the
result is well defined or not ...
I'd suggest doing the grouping/ordering numerically rather than
textually. For instance,
select
to_char(date_trunc('month', myCol), 'Mon YY')
from
myTable
group by
date_trunc('month', myCol)
order by
date_trunc('month', myCol);
Now this assumes you really want a time-based ordering, which the quoted
example doesn't give --- you've got month sorting to the left of year,
is that really what you want? If it is then you'd need to go
group by
date_trunc('month', myCol)
order by
to_char(date_trunc('month', myCol), 'MM YYYY')
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match