Re: [SQL] Date type select

From: George Moga <george(at)flex(dot)ro>
To: Paulo Roberto Kappke <paulok(at)cyclades(dot)com(dot)br>, SQL PostgreSQL <pgsql-sql(at)postgreSQL(dot)org>
Subject: Re: [SQL] Date type select
Date: 1999-09-22 15:37:21
Message-ID: 37E8F7B1.BB1B2F6F@flex.ro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Paulo Roberto Kappke wrote:

> Hi all,
>
> I'm having a problem to make a select statement with a date type field.
>
> I have a table with a field named date_in and this field is a date type.
> Well, I need to do a select where the month is 09 and the year is 1999.
> I tried:
>
> SELECT * FROM calls WHERE date_in LIKE '09%1999' ORDER BY date_in
> or
> SELECT * FROM calls WHERE date_in LIKE '09-__-1999' ORDER BY date_in
> or
> SELECT * FROM calls WHERE date_in LIKE '09%' AND date_in LIKE '%1999'
> ORDER BY date_in
>
> using psql command and I received the following message:
>
> ERROR: There is more than one possible operator '~~' for types 'date'
> and 'unknown'
> You will have to retype this query using an explicit cast
>
> Could anybody help me ?
>
> Thanks in advance,
> Paulo Kappke
> Cyclades Brazil
>
> ************

Try this:

select * from calls where date_part('month', date_in::datetime) = '09' and
date_part('year', date_in::datetime) = '1999' order by date_in

I use PostgreSQL 6.5.1 on RedHat Linux 6.0.

--
Best,
George Moga,
george(at)flex(dot)ro
george(at)cicnet(dot)ro

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Hutton, Rob 1999-09-22 16:21:53 RE: [SQL] Re: [INTERFACES] JDBC and getting just assigned serial number
Previous Message Herouth Maoz 1999-09-22 15:16:36 Re: [INTERFACES] JDBC and getting just assigned serial number