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

Re: explicit casts

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Cc: Iuri Sampaio <iuri(dot)sampaio(at)gmail(dot)com>
Subject: Re: explicit casts
Date: 2011-01-06 02:33:27
Message-ID: 201101051833.28052.adrian.klaver@gmail.com (view raw or flat)
Thread:
Lists: pgsql-sql
On Wednesday 05 January 2011 5:22:30 pm Iuri Sampaio wrote:
> So far,
> I could write the following query
>
> select to_char(trunc(to_date('2010-01-02', 'yyyy-mm-dd'), 'Month'),
> 'fmMonth') as month,
> to_char(trunc(to_date('2010-01-02', 'yyyy-mm-dd'), 'Month'), 'YYYY') as
> year,
> to_char(trunc(to_date('2010-01-02', 'yyyy-mm-dd'), 'Month'), 'J') as
> first_julian_date_of_month,
> to_char(last_day('2010-01-02')::date, 'DD') as num_days_in_month,
> to_char(trunc(to_date('2010-01-02', 'yyyy-mm-dd'), 'Month'), 'D') as
> first_day_of_month,
> to_char(last_day('2010-01-02')::date, 'DD') as last_day,
> trunc(add_months(to_date('2010-01-02', 'yyyy-mm-dd'), 1),'Day') as
> next_month,
> trunc(add_months(to_date('2010-01-02', 'yyyy-mm-dd'), -1),'Day') as
> prev_month,
> trunc(to_date('2010-01-02', 'yyyy-mm-dd'), 'year') as beginning_of_year,
> to_char(last_day(add_months('2010-01-02', -1))::date, 'DD') as
> days_in_last_month,
> to_char(add_months(to_date('2010-01-02', 'yyyy-mm-dd'), 1), 'fmMonth')
> as next_month_name,
> to_char(add_months(to_date('2010-01-02', 'yyyy-mm-dd'), -1), 'fmMonth')
> as prev_month_name
> from dual
>
>
> But i still miss some lines in order to properly explicit casts in the
> query
>
> cheers,
> iuri


My guess is you upgraded from a version prior to 8.3. In 8.3 many of the implied 
casts where removed, so you probably have to go over your code and make the 
corrections.
Go here for more detail:
http://www.postgresql.org/docs/8.4/interactive/release-8-3.html
Section
 E.21.2.1. General

A temporary solution can be found here:
http://petereisentraut.blogspot.com/2008/03/readding-implicit-casts-in-postgresql.html

An important tip from the blog-
"The gist was, only restore the casts you need, not all of them."

-- 
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

pgsql-sql by date

Next:From: Jasmin DizdarevicDate: 2011-01-07 10:07:03
Subject: Re: return records with more than one occurrences
Previous:From: Adrian KlaverDate: 2011-01-06 02:20:49
Subject: Re: explicit casts

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