Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 8CD511337BCF for ; Wed, 5 Jan 2011 22:21:01 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 21884-05 for ; Thu, 6 Jan 2011 02:20:55 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-vw0-f46.google.com (mail-vw0-f46.google.com [209.85.212.46]) by mail.postgresql.org (Postfix) with ESMTP id 85CA71337B92 for ; Wed, 5 Jan 2011 22:20:51 -0400 (AST) Received: by vws16 with SMTP id 16so6700874vws.19 for ; Wed, 05 Jan 2011 18:20:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date :user-agent:cc:references:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:message-id; bh=0NSJrBbPaP52HX7QCBNBf1edajERJYgPJtNdwqlOJBY=; b=pHTURSM+PRmJ+ljYOanbQQKHCgv4k5dgR8kQb7G5yNeRYYgOktFWR8YlxKAdXoeXlM PnYYljzLsroAbEHTXuuNErA6pwV47ecg1KncwkbIEWKzuYpNEdJgXZJvG4kTL32v82zU gRYJ6NFL09SAJY5OEBh224WsNoPXvjkbWtym0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding :content-disposition:message-id; b=VrgLcyrvdNM1+mlLgWNSrUCo9+VBcT/EBcttiTXDhHNa5pUxmOCT63E/SlrgWilqiB GkzzDJZchPKDx8IM7Y+YS0Hhu+tBwp/j43XPVXCQRMd6VAz9A6rMc3lXg99NEIm67W79 tVpe4atpV/6bpI8xFUBUCHuATX5zkbG6G/KxI= Received: by 10.220.203.132 with SMTP id fi4mr6727484vcb.125.1294280451497; Wed, 05 Jan 2011 18:20:51 -0800 (PST) Received: from tucker.local (c-24-17-164-54.hsd1.wa.comcast.net [24.17.164.54]) by mx.google.com with ESMTPS id e18sm8986534vbm.15.2011.01.05.18.20.49 (version=SSLv3 cipher=RC4-MD5); Wed, 05 Jan 2011 18:20:50 -0800 (PST) From: Adrian Klaver Reply-To: adrian.klaver@gmail.com To: pgsql-sql@postgresql.org Subject: Re: explicit casts Date: Wed, 5 Jan 2011 18:20:49 -0800 User-Agent: KMail/1.9.10 Cc: Iuri Sampaio References: <4D250BC2.2060207@gmail.com> In-Reply-To: <4D250BC2.2060207@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201101051820.49646.adrian.klaver@gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.588 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RFC_ABUSE_POST=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201101/10 X-Sequence-Number: 34957 On Wednesday 05 January 2011 4:24:34 pm Iuri Sampaio wrote: > Hi there, > > I installed postgresql 8.4 on my box and now i have troubles with the > following query regarding explicit casts. > > select to_char(trunc(to_date(:the_date, 'yyyy-mm-dd'), 'Month'), > 'fmMonth') as month, > to_char(trunc(to_date(:the_date, 'yyyy-mm-dd'), 'Month'), 'YYYY') > as year, > to_char(trunc(to_date(:the_date, 'yyyy-mm-dd'), 'Month'), 'J') as > first_julian_date_of_month, > to_char(last_day(to_date(:the_date, 'yyyy-mm-dd')), 'DD') as > num_days_in_month, > to_char(trunc(to_date(:the_date, 'yyyy-mm-dd'), 'Month'), 'D') as > first_day_of_month, > to_char(last_day(to_date(:the_date, 'yyyy-mm-dd')), 'DD') as last_day, > trunc(add_months(to_date(:the_date, 'yyyy-mm-dd'), 1),'Day') as > next_month, > trunc(add_months(to_date(:the_date, 'yyyy-mm-dd'), -1),'Day') as > prev_month, > trunc(to_date(:the_date, 'yyyy-mm-dd'), 'year') as beginning_of_year, > to_char(last_day(add_months(to_date(:the_date, 'yyyy-mm-dd'), -1)), > 'DD') as days_in_last_month, > to_char(add_months(to_date(:the_date, 'yyyy-mm-dd'), 1), 'fmMonth') > as next_month_name, > to_char(add_months(to_date(:the_date, 'yyyy-mm-dd'), -1), > 'fmMonth') as prev_month_name > from dual > > the value assigned to the variable :the_date is '2010-01-05' > > The error is > > Error: Ns_PgExec: result status: 7 message: ERROR: function > to_date(timestamp with time zone, unknown) does not exist > LINE 1: select to_date(date_trunc('month',add_months( $1 ,1)),'YYYY-... > ^ > HINT: No function matches the given name and argument types. You might > need to add explicit type casts. > QUERY: select to_date(date_trunc('month',add_months( $1 > ,1)),'YYYY-MM-DD') - 1 > CONTEXT: PL/pgSQL function "last_day" line 6 at SQL statement > > > how would i apply the following solution > > date_trunc('month', p_date_in + interval '1 month')::date - 1 > > to fix the query above? > > cheers, > iuri If I am following this right the problem is in the last_day function and in particular the return value of the add_months function used in the date_trunc(). To be sure we would need to see those functions. As a shot in the dark: select to_date(date_trunc('month',add_months( $1 ,1)::date)... -- Adrian Klaver adrian.klaver@gmail.com