Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 8C34FB5DBCA for ; Mon, 26 Sep 2011 22:38:39 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 00576-07 for ; Tue, 27 Sep 2011 01:38:33 +0000 (UTC) X-Greylist: delayed 00:06:37.689011 by SQLgrey-1.8.0-rc2 Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.23]) by mail.postgresql.org (Postfix) with SMTP id ECF68B5D803 for ; Mon, 26 Sep 2011 22:38:32 -0300 (ADT) Received: (qmail invoked by alias); 27 Sep 2011 01:31:49 -0000 Received: from p57A5D48D.dip.t-dialin.net (EHLO [192.168.1.20]) [87.165.212.141] by mail.gmx.net (mp007) with SMTP; 27 Sep 2011 03:31:49 +0200 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX19LFWNO6MRLzdM4iHC0GkQ125CXBLvHlT2mp38r9Q 8UQrwUql7lhGIF Message-ID: <4E812787.1080002@gmx.net> Date: Tue, 27 Sep 2011 03:31:51 +0200 From: Andreas User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: how to calculate differences of timestamps? Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.393 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RP_MATCHES_RCVD=-0.504, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201109/81 X-Sequence-Number: 35881 How could I calculate differences of timestamps in a log-table? Table log ( user_id integer, login boolean, ts timestamp ) So login = true would be a login-event and login = false a logout. Is there a way to find the matching login/logout to calculate the difference? Or is there a better table "design" to do this?