Re: How to specify the beginning of the month in Postgres SQL syntax? - Mailing list pgsql-sql

From sqllist
Subject Re: How to specify the beginning of the month in Postgres SQL syntax?
Date
Msg-id 002101c3bede$ed1e29e0$0f32a8c0@denisnew
Whole thread Raw
In response to How to specify the beginning of the month in Postgres SQL syntax?  (jeff@dnuk.com)
Responses Re: How to specify the beginning of the month in Postgres SQL syntax?  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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@dnuk.com>
To: <pgsql-sql@postgresql.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



pgsql-sql by date:

Previous
From: Paul Thomas
Date:
Subject: Re: How to specify the beginning of the month in Postgres SQL syntax?
Next
From: Olivier Hubaut
Date:
Subject: Bug in JDBC CREATE FUNCTION syntax?