Skip site navigation (1) Skip section navigation (2)

Re: Age Fucntion

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: brian stapel <brians_224(at)hotmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Age Fucntion
Date: 2007-01-16 20:46:56
Message-ID: 24396.1168980416@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-novice
brian stapel <brians_224(at)hotmail(dot)com> writes:
>  return date_part('year',age(timestamp dt_hiredate))*365 + ...

This is not correct syntax, you should just write age(dt_hiredate).

I think you made an incorrect extrapolation from the syntax sometimes
used for literal timestamp constants, viz
		timestamp 'whatever'
We support that because it's in the SQL spec, but it doesn't generalize
to anything except literal constants.  If you needed to convert the
variable dt_hiredate to timestamp (which you do not, in this example,
because it already is that type), you'd write either
		cast(dt_hiredate as timestamp)
		dt_hiredate::timestamp
The former is the SQL-spec syntax for a runtime type conversion, the
latter a traditional Postgres abbreviation.

BTW, the cast and :: syntaxes work fine for literals too.  I tend to
avoid the type-name-first syntax for literals, just because it doesn't
generalize.

			regards, tom lane

In response to

pgsql-novice by date

Next:From: Hackenberg, RickDate: 2007-01-16 21:07:28
Subject: Problems with SSL
Previous:From: brian stapelDate: 2007-01-16 20:02:10
Subject: Age Fucntion

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group