pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: sqllist <sqllist@coralindia.com>
To: pgsql-sql@postgresql.org
Cc: jeff@dnuk.com
Subject: Re: How to specify the beginning of the month in Postgres SQL syntax?
Date: Wed, 10 Dec 2003 11:01:54 +0530
Message-ID: <002101c3bede$ed1e29e0$0f32a8c0@denisnew> (raw)
References: <t6k6tv8unr1dm7kpeb275ca0t9in2i910h@4ax.com>


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




view thread (5+ messages)  latest in thread

Message-ID: <002101c3bede$ed1e29e0$0f32a8c0@denisnew>
Permalink:  ../002101c3bede$ed1e29e0$0f32a8c0@denisnew/
Also on:    postgresql.org/message-id/002101c3bede$ed1e29e0$0f32a8c0@denisnew

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sqllist@coralindia.com, jeff@dnuk.com
  Subject: Re: How to specify the beginning of the month in Postgres SQL syntax?
  In-Reply-To: <002101c3bede$ed1e29e0$0f32a8c0@denisnew>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox