Re: Ordering problem with varchar (DESC)

From: Alexandre Leclerc <aleclerc(at)ipso(dot)ca>
To: Brandon Aiken <BAiken(at)winemantech(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Ordering problem with varchar (DESC)
Date: 2007-01-31 18:41:17
Message-ID: 45C0E2CD.4000701@ipso.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Brandon Aiken a écrit :
> As others have said, VARCHAR is the incorrect data type to be using
> here. You should either be using INTERVAL or TIMESTAMP depending on
> what you want. You can even combine date and time into a single
> TIMESTAMP field. Only use VARCHAR when no other data type will do.

I dearly would like to do that, but it is impossible (because of the
software/technology that uses the database). I would have use a
TIMESTAMP for that.

> Try "SELECT * from t1 ORDER BY date, time;", and I suspect you will get:
> date (date type) time (varchar) data
> 2007-01-17 8h40 d1
> 2007-01-30 12h00 d3
> 2007-01-30 13h45 d4
> 2007-01-30 17h20 d5
> 2007-01-30 9h30 d2
>
> To use your current schema, you need to zero-fill your hours, so 9h30
> needs to be 09h30 and so forth.

Exactly. This is sorted that way. This is what I'll do, inserting a 0.

Best regards.

--
Alexandre Leclerc

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alexandre Leclerc 2007-01-31 18:41:45 Re: Ordering problem with varchar (DESC)
Previous Message Jeff Davis 2007-01-31 18:37:34 Re: Any Plans for cross database queries on the same server?