Re: mysql query to postgres Timediff

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: franrtorres77 <franrtorres77(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: mysql query to postgres Timediff
Date: 2010-12-02 13:03:24
Message-ID: AANLkTiko0o0t1e-m9RnPS4_W=0yCkqEESCfYV4_8fvgE@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

PostgreSQL hasn't a timediff function and hasn't a session variables.
You can see how can be implemented this function in pg
http://okbob.blogspot.com/2009/08/mysql-functions-for-postgresql.html.
If you can compare values from different rows, you have to have a pg
>= 8.4 with window functions or you have to use a stored procedure.

http://www.postgresql.org/docs/8.4/static/functions-window.html

Regards

Pavel Stehule

2010/12/2 franrtorres77 <franrtorres77(at)gmail(dot)com>:
>
> Hello
>
> I have the next query in mysql to get the time difference from two rows, but
> I would like to implement it in postgres, but I'm getting some errors when I
> try to query it.
>
> select speed,mobile,date,
> timediff(@nexttime,date) as tdiff2, (@nexttime:=date) as Next
> from positions
> where speed=0 and mobile = 1883 and date >(now() - interval 2 hour)
>
> I have changed the last part to: (now() - interval '2 hours') but I go on
> getting another error in the Timediff command.
>
> What I want to do is something like this:
>
> 14-12-2010 20:25:40
> 14-12-2010 20:26:45
>
> So, the result would be: the substract of both dates to get how much time
> have spent from the last date
> ,  so it will result 00:01:05 minutes
>
> Can anyone help me please?
>
> Best regards.
> --
> View this message in context: http://postgresql.1045698.n5.nabble.com/mysql-query-to-postgres-Timediff-tp3289115p3289115.html
> Sent from the PostgreSQL - general mailing list archive at Nabble.com.
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Samba 2010-12-02 14:03:43 Re: [REPOST] plpgsql : looping over multidimensional array : getting NULL for subdimension
Previous Message Andrus 2010-12-02 12:34:13 Re: ***SPAM*** Re: How to find correct locale name for CREATEDATABASE