Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The syntax is your <a href="http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC" rel="nofollow"><code>date_trunc</code></a> is a bit off:</p> <pre><code>select * from callhistory where created &gt; date_trunc('minute', current_timestamp - interval '5' minute) </code></pre> <p>You could also use <a href="http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-TABLE" rel="nofollow"><code>now()</code> in place of <code>current_timestamp</code></a>:</p> <pre><code>select * from callhistory where created &gt; date_trunc('minute', now() - interval '5' minute) </code></pre> <p>And an example:</p> <pre><code>=&gt; create table stuff (created timestamp not null); =&gt; insert into stuff (created) values (current_timestamp); -- Wait a could seconds... =&gt; insert into stuff (created) values (current_timestamp); =&gt; select * from stuff where created &gt; date_trunc('minute', current_timestamp - interval '5' minute); created ---------------------------- 2011-06-01 11:32:55.672027 2011-06-01 11:33:00.182953 =&gt; select * from stuff where created &gt; date_trunc('minute', current_timestamp - interval '7' day); created ---------------------------- 2011-06-01 11:32:55.672027 2011-06-01 11:33:00.182953 </code></pre> <p><strong>UPDATE</strong>: Looks like PostgreSQL version 8 is a little stricter on the format for <code>interval</code>, the <a href="http://www.postgresql.org/docs/current/static/functions-datetime.html" rel="nofollow">fine manual</a> says that you should use <code>interval '$n $unit'</code> where <code>$n</code> is the number of things and <code>$unit</code> is the time unit. Version 9 allows you to say <code>interval '$n' $unit</code> without complaint but version 8 converts your interval to 0 if you don't use the documented format. So, you should use this for both version 8 and version 9:</p> <pre><code>select * from callhistory where created &gt; date_trunc('minute', current_timestamp - interval '5 minute') </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload