Re: How to specify the beginning of the month in Postgres SQL syntax?

From: "sqllist" <sqllist(at)coralindia(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Cc: <jeff(at)dnuk(dot)com>
Subject: Re: How to specify the beginning of the month in Postgres SQL syntax?
Date: 2003-12-10 05:31:54
Message-ID: 002101c3bede$ed1e29e0$0f32a8c0@denisnew
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


Hi Jeff,

You can use

WHERE date < to_date( to_char(current_date,'yyyy-MM') || '-01','yyyy-mm-dd')

Thanx

Denis

----- Original Message -----
From: <jeff(at)dnuk(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Sent: Sunday, December 07, 2003 9:46 PM
Subject: [SQL] How to specify the beginning of the month in Postgres SQL
syntax?

> Hello,
>
> I need to create a view in Postgres that has a where clause of the
> date < beginning of month.
>
> i.e.:
> SELECT supplier_number, Sum(amount) AS due
> FROM purchase_orders
> WHERE date < '2003-12-1' AND paid = 0
> GROUP BY supplier_number
> ORDER BY supplier_number ASC
>
>
> As you can see, I've specified the 1st of December this year as the
> where clause. What I want is an SQL statement that automatically
> generates the first of the month. How do I do this?
>
> Thanks.
>
> ---------------------------(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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Olivier Hubaut 2003-12-10 08:58:14 Bug in JDBC CREATE FUNCTION syntax?
Previous Message Paul Thomas 2003-12-10 00:52:56 Re: How to specify the beginning of the month in Postgres SQL syntax?