Re: SQL and function reference? - Mailing list pgsql-novice

From Alexander Borkowski
Subject Re: SQL and function reference?
Date
Msg-id 41F8271B.7050606@abri.une.edu.au
Whole thread Raw
In response to Re: SQL and function reference?  ("Rodolfo J. Paiz" <rpaiz@simpaticus.com>)
Responses Re: SQL and function reference?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
> The idea here is to have a formula that says "select * from flights
> where date was less than 30 days ago"  and have that formula work
> properly.

How about:

select *
from flights
where date < cast(current_date + interval '30 days ago' as date);

(assuming there is a date column (of type date) on flights).

  So if I want to subtract two dates for this purpose, then I am
> going to need a today() function which I also have not found.
>
> I see now how the extract(epoch from interval) could be used, but then
> why is there no extract(days|months|hours from interval), or why can I
> not format an interval as "XXXXX seconds" or "YYY days"? Would make
> things so much simpler!

You can do this. For example

select current_timestamp + interval '1000000 seconds';

You can find the documentation on how to use the interval type in "Data
Types" / "Date/Time Types".

Cheers,

Alex

pgsql-novice by date:

Previous
From:
Date:
Subject: Re: Postgres database access problem
Next
From: Tom Lane
Date:
Subject: Re: SQL and function reference?