X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 6A0D6D1B46D for ; Sun, 7 Dec 2003 19:59:28 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 90786-02 for ; Sun, 7 Dec 2003 15:59:01 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id EAFF7D1B452 for ; Sun, 7 Dec 2003 15:58:59 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id hB7JwwbI057791 for ; Sun, 7 Dec 2003 19:58:58 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id hB7JZM20055455 for pgsql-sql@postgresql.org; Sun, 7 Dec 2003 19:35:22 GMT From: CoL X-Newsgroups: comp.databases.postgresql.sql Subject: Re: How to specify the beginning of the month in Postgres SQL syntax? Date: Sun, 07 Dec 2003 20:38:53 +0100 Organization: Hub.Org Networking Services Lines: 30 Message-ID: References: Reply-To: col@mportal.hu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6b) Gecko/20031129 X-Accept-Language: en-us, en In-Reply-To: To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/70 X-Sequence-Number: 16236 hi jeff@dnuk.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.