pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
age() function usage
3+ messages / 2 participants
[nested] [flat]

* age() function usage
@ 2008-01-25 19:06  Marcin Krawczyk <jankes.mk@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Marcin Krawczyk @ 2008-01-25 19:06 UTC (permalink / raw)
  To: pgsql-sql

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').

Thanks in advance
mk

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: age() function usage
@ 2008-01-25 19:41  Scott Marlowe <scott.marlowe@gmail.com>
  parent: Marcin Krawczyk <jankes.mk@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Scott Marlowe @ 2008-01-25 19:41 UTC (permalink / raw)
  To: Marcin Krawczyk <jankes.mk@gmail.com>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: age() function usage
@ 2008-01-25 19:53  Marcin Krawczyk <jankes.mk@gmail.com>
  parent: Scott Marlowe <scott.marlowe@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Marcin Krawczyk @ 2008-01-25 19:53 UTC (permalink / raw)
  To: Scott Marlowe <scott.marlowe@gmail.com>; +Cc: pgsql-sql

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
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2008-01-25 19:53 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-01-25 19:06 age() function usage Marcin Krawczyk <jankes.mk@gmail.com>
2008-01-25 19:41 ` Scott Marlowe <scott.marlowe@gmail.com>
2008-01-25 19:53   ` Marcin Krawczyk <jankes.mk@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox