Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id DBFC66326DA for ; Tue, 5 Jan 2010 22:48:52 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 36466-05 for ; Wed, 6 Jan 2010 02:48:33 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pw0-f44.google.com (mail-pw0-f44.google.com [209.85.160.44]) by mail.postgresql.org (Postfix) with ESMTP id 15A366328D7 for ; Tue, 5 Jan 2010 22:48:41 -0400 (AST) Received: by pwi15 with SMTP id 15so11661704pwi.3 for ; Tue, 05 Jan 2010 18:48:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=pDzdqOXZ49NHJfrfFCr9FmWCqZvw4/8fGOVgDTytbpo=; b=ZaIlpc7a/TDBwfUhJ/zbQ5bexou3Oyknx1nUNXLLoCxGtF99+uNhm2ADiwznrgpT8v CRX54nuzSNPUx78d53vKPPFyiuj6cemBWYB1fatga1c2d/9ZQb4AxGC4lOSKF/lX5QHK ol3mIR0aIYwtWT78ut/J4cIPE8QLh4IY0LNFI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=nk3QuV9T5qjfa1Uw5wkphuKYauTy8cSdMq70NVjm1ivmPC53CusS11ytjbQZxYR2W0 aHZu39lDNTizLpGvy9gj8/BlI64luhbyvsUnN7CTBCXRWjl8XAmBQEqgw8k54pSqR4co GdON5VozFyJmGYqJsaJO3/PjscNmQwYNzcfTs= Received: by 10.142.55.20 with SMTP id d20mr15833706wfa.322.1262746120048; Tue, 05 Jan 2010 18:48:40 -0800 (PST) Received: from ?192.168.2.65? (office.squiz.net [203.206.128.174]) by mx.google.com with ESMTPS id 23sm16668876pzk.0.2010.01.05.18.48.37 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 05 Jan 2010 18:48:38 -0800 (PST) Message-ID: <4B43FA01.2030406@gmail.com> Date: Wed, 06 Jan 2010 13:48:33 +1100 From: Chris User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: getting extract to always return number of hours References: <4B43E887.6040402@gmail.com> In-Reply-To: <4B43E887.6040402@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.75 tagged_above=-10 required=5 tests=AWL=-2.439, BAYES_50=0.001, FH_DATE_PAST_20XX=3.188 X-Spam-Level: X-Archive-Number: 201001/4 X-Sequence-Number: 33540 Chris wrote: > Hi, > > I'm trying to get extract() to always return the number of hours between > two time intervals, ala: > > => create table t1(timestart timestamp, timeend timestamp); > => insert into t1(timestart, timeend) values ('2010-01-01 00:00:00', > '2010-01-02 01:00:00'); > > => select timeend - timestart from t1; > ?column? > ---------------- > 1 day 01:00:00 > (1 row) > > to return 25 hours. I ended up with select extract('days' from x) * 24 + extract('hours' from x) from (select (timeend - timestart) as x from t1) as y; mainly because t1 is rather large so I didn't want to run the end - start calculation multiple times. -- Postgresql & php tutorials http://www.designmagick.com/