Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 9082B2E350F for ; Fri, 25 Jan 2008 15:53:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 94806-07 for ; Fri, 25 Jan 2008 15:53:12 -0400 (AST) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.251]) by postgresql.org (Postfix) with ESMTP id 3D8E52E3527 for ; Fri, 25 Jan 2008 15:53:14 -0400 (AST) Received: by an-out-0708.google.com with SMTP id c36so184300ana.33 for ; Fri, 25 Jan 2008 11:53:13 -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:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=CXKNJBRDRE1+NS9jx3hPU+IBX+aqGm5U/u8w6QGR0K8=; b=VWP51hvmUfZenFQAsUwsjQx+flyX0DkQxQX0ZScsLHKOjBr7ItnAZDw63jOL4bpGaeV5AFq2OkAY1qVRPnrYhINAWyd8mv6LA0DhA/rW2el6i+PMsMcPb2BIQZMzJPm/4Lzn5pqWxQ9dj8efQqi0+UwfYrr1pedhUOC3WkaXe6w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=JQ0K6/OPwSYJa8kfbwsJPQCuNFR48HmlzyPerwB0J6/MT6P0HI0OiTWq2yigbtlMW/OZKiGKG6NhvXzewS9Ou3Pr27tgW1jyIYehHqdcub4Pk+O8duEBvkM9kU5v9kP6HA39EFvzmxROodvpan9/YEf74tPzHJNXvUoqYNgeudw= Received: by 10.100.172.17 with SMTP id u17mr5038890ane.27.1201290792670; Fri, 25 Jan 2008 11:53:12 -0800 (PST) Received: by 10.100.92.16 with HTTP; Fri, 25 Jan 2008 11:53:12 -0800 (PST) Message-ID: <95f6bf9b0801251153s303f650ave9d4ff289ccee82@mail.gmail.com> Date: Fri, 25 Jan 2008 20:53:12 +0100 From: "Marcin Krawczyk" To: "Scott Marlowe" Subject: Re: age() function usage Cc: pgsql-sql@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1462_32681816.1201290792664" References: <95f6bf9b0801251106h6577fa94j508574db50030b53@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/204 X-Sequence-Number: 30057 ------=_Part_1462_32681816.1201290792664 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Heh, that was easy, I must have been working for too long... :) Thanks 2008/1/25, Scott Marlowe : > > On Jan 25, 2008 1:06 PM, Marcin Krawczyk wrote: > > Hi all. I am trying to determine the way to pass a variable/field value > to > > an age() function, query looks something like: > > > > SELECT age(timestamp data_zakonczenia_fakt) FROM kip_pracownicy_umowy > WHERE > > id_pracownika = 8 > > > > data_zakonczenia_fakt being char column equal to say '1993-11-30'. > > Such approach won't work, can anyone tell me the way to do it? > > > > SELECT age(timestamp '1993-11-30') works great. > > Same story with age(timestamp '2008-01-01', timestamp '1993-11-30'). > > You need an explicit cast: > > SELECT age(data_zakonczenia_fakt::timestamp) FROM kip_pracownicy_umowy > WHERE id_pracownika = 8 > ------=_Part_1462_32681816.1201290792664 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Heh, that was easy, I must have been working for too long... :) Thanks



2008/1/25, Scott Marlowe <scott.marlowe@gmail.com>:
On Jan 25, 2008 1:06 PM, Marcin Krawczyk <jankes.mk@gmail.com> wrote:
> Hi all. I am trying to determine the way to pass a variable/field value to
> an age() function, query looks something like:
>
> SELECT age(timestamp data_zakonczenia_fakt) FROM kip_pracownicy_umowy WHERE
> id_pracownika = 8
>
> data_zakonczenia_fakt being char column equal to say '1993-11-30'.
> Such approach won't work, can anyone tell me the way to do it?
>
> SELECT age(timestamp '1993-11-30') works great.
> Same story with age(timestamp '2008-01-01', timestamp '1993-11-30').

You need an explicit cast:

SELECT age(data_zakonczenia_fakt::timestamp) FROM kip_pracownicy_umowy
WHERE id_pracownika = 8

------=_Part_1462_32681816.1201290792664--