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

From: CoL <col(at)mportal(dot)hu>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to specify the beginning of the month in Postgres SQL syntax?
Date: 2003-12-07 19:38:53
Message-ID: bqvvdq$1m4r$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

hi

jeff(at)dnuk(dot)com wrote, On 12/7/2003 5:16 PM:

> 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?
>

a simple way:
create function month_begin() returns date as '
SELECT to_date(current_date,'YYYY-MM');
' language sql STABLE;

... where date < month_begin() ....

C.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ganesan Kanavathy 2003-12-08 12:52:03 Field Size
Previous Message jeff 2003-12-07 16:16:44 How to specify the beginning of the month in Postgres SQL syntax?