Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id A55361337B8B for ; Wed, 5 Jan 2011 21:22:39 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 43065-10 for ; Thu, 6 Jan 2011 01:22:32 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-yw0-f46.google.com (mail-yw0-f46.google.com [209.85.213.46]) by mail.postgresql.org (Postfix) with ESMTP id 371021337B82 for ; Wed, 5 Jan 2011 21:22:32 -0400 (AST) Received: by ywl5 with SMTP id 5so6248248ywl.19 for ; Wed, 05 Jan 2011 17:22:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=DfMZmVe4j/WWZFeUO4oB0KD2XUmoj8rlpDP+GtArE/w=; b=B9Ob3Bm6k1yRJ1OFCzB1qp0mP/Hid1Nza1q31VqZJvro4/9EXVU94jEp+0WFJEApBI zvf5r5qvfRNzGSqgxAne2HnbI6sFeEJXeUcaH/re6HA0Nhkl9XsphBpRrWxCCywkw+0k /LOPp7DaaXB+tBds+z1noVaKG+HauV1pIr3xA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=mCY+3bnvEmDioWB1GMRxWNmBLiKXib0rceHP2FI//l4Ho/Wv6t8ultqg4QdLYPDUrs Cdx5cTISDwlLQGX6vSl9IqMtwv2sE2rJvfYQuhZqe9FQVSVW2LMdY1BwKTxqJXnTYzUi bdHjb1VC3rXFFsMR0eBns8Y8kTGNdGwMwHa44= Received: by 10.100.132.19 with SMTP id f19mr4455070and.265.1294276952618; Wed, 05 Jan 2011 17:22:32 -0800 (PST) Received: from [192.168.1.100] ([201.87.45.222]) by mx.google.com with ESMTPS id b19sm22034582ana.27.2011.01.05.17.22.31 (version=SSLv3 cipher=RC4-MD5); Wed, 05 Jan 2011 17:22:32 -0800 (PST) Message-ID: <4D251956.5050309@gmail.com> Date: Wed, 05 Jan 2011 23:22:30 -0200 From: Iuri Sampaio User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: explicit casts References: <4D250BC2.2060207@gmail.com> In-Reply-To: <4D250BC2.2060207@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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/9 X-Sequence-Number: 34956 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 On 01/05/2011 10:24 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