pulling year out of a timestamp

From: Kirk Wythers <wythe001(at)umn(dot)edu>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: pulling year out of a timestamp
Date: 2013-04-11 15:50:53
Message-ID: 82C9BE41-B98D-4FDD-BC79-5A75D4381B06@umn.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am trying to perform a join between two tables where I need to join "year" in table 1 with the year component of a timestamp in table 2.

Something like this:

table1.year = table2.timestamp
where timestamp has the format: "2009-01-01 00:00:00"

I've tried

date_trunc('year', table2.timestamp) = table1.year

but am getting this error:

ERROR: operator does not exist: timestamp without time zone = integer
LINE 15: AND date_trunc('year', _60min_user.time2) = power.year
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.

Am I barking up the completely wrong tree?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ryan Kelly 2013-04-11 15:55:18 Re: pulling year out of a timestamp
Previous Message Shaun Thomas 2013-04-11 15:41:40 Re: Update