Re: How to return an Int4 when subtracting dates/timestamps

From: Tim Landscheidt <tim(at)tim-landscheidt(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to return an Int4 when subtracting dates/timestamps
Date: 2010-05-18 23:22:49
Message-ID: m3y6fglrqu.fsf@passepartout.tim-landscheidt.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andre Lopes <lopes80andre(at)gmail(dot)com> wrote:

> I need to return an Int4 when I do this king of select

> [code]
> select CURRENT_DATE - '2009-12-31' from tbl_sometable
> [/code]

> This select returns an Interval. How can I return an Integer? Like '138'

That expression returning an interval would be contradictory
to the documentation and a simple test:

| tim=# SELECT CURRENT_DATE - '2009-12-31';
| ?column?
| ----------
| 138
| (1 Zeile)

| tim=# SELECT CURRENT_DATE::TIMESTAMP - '2009-12-31';
| ?column?
| ----------
| 138 days
| (1 Zeile)

| tim=#

So how far away from "this kind of select" is your actual
query?

Tim

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Brad Ediger 2010-05-19 01:15:18 ERROR: unrecognized time zone name: "UTC"
Previous Message Andre Lopes 2010-05-18 22:14:04 How to return an Int4 when subtracting dates/timestamps