pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Guillaume Perréal <perreal@lyon.cemagref.fr>
To: Antti Linno <alligator@all.ee>
Cc: pgsql-sql@postgresql.org
Subject: Re: extract last months data
Date: Wed, 28 Jun 2000 13:35:03 +0200
Message-ID: <3959E2E7.D19FB802@lyon.cemagref.fr> (raw)
References: <Pine.LNX.4.04.10006281254410.9950-100000@all.ee>

Antti Linno wrote:

> Lo.
>  Today I digged in manuals and other docs, but didn't find any hint, how
> to get data from table, where some cols are in date or datetime format,
> and the data was about last month, or about special month.
> Psql help was unhelpful too.
> Here's example:
> In table workers is data with different date. When I need to make summary,
> I just want to extract last months data, but I don't know whether the
> month ended with 29,30 or 31 (external program, that uses postgres),
> so I cant use
> select * from workers where date<31.1.2000 and date>1.1.2000
> I think I can get month and year number at least, but I can't use mday
> attribute.

Try:
    SELECT * FROM workers WHERE DATE_TRUNC('month', date) = '2000-31-1'::DATE;

See the manual for exact syntax of DATE_TRUNC.

> All suggestions are welcome :P
>
> Stucked alligator :)

--
Guillaume Perréal - Stagiaire MIAG
Cemagref (URH), Lyon, France
Tél: (+33) 4.72.20.87.64





view thread (3+ messages)  latest in thread

Message-ID: <3959E2E7.D19FB802@lyon.cemagref.fr>
Permalink:  ../3959E2E7.D19FB802@lyon.cemagref.fr/
Also on:    postgresql.org/message-id/3959E2E7.D19FB802@lyon.cemagref.fr

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: perreal@lyon.cemagref.fr, alligator@all.ee
  Subject: Re: extract last months data
  In-Reply-To: <3959E2E7.D19FB802@lyon.cemagref.fr>
  References: <Pine.LNX.4.04.10006281254410.9950-100000@all.ee> <3959E2E7.D19FB802@lyon.cemagref.fr>

* 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