Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 5F36463347F for ; Fri, 11 Jun 2010 06:42:49 -0300 (ADT) 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 63881-09 for ; Fri, 11 Jun 2010 09:42:41 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og119.obsmtp.com (exprod7og119.obsmtp.com [64.18.2.16]) by mail.postgresql.org (Postfix) with SMTP id 5CED963257B for ; Fri, 11 Jun 2010 06:42:41 -0300 (ADT) Received: from source ([74.125.82.50]) by exprod7ob119.postini.com ([64.18.6.12]) with SMTP ID DSNKTBIFDzOr7A+rvmA61KfLDcd1/SRm/Xjp@postini.com; Fri, 11 Jun 2010 02:42:40 PDT Received: by wwg30 with SMTP id 30so692995wwg.37 for ; Fri, 11 Jun 2010 02:42:38 -0700 (PDT) Received: by 10.216.159.3 with SMTP id r3mr428360wek.26.1276249358731; Fri, 11 Jun 2010 02:42:38 -0700 (PDT) Received: from [192.168.1.117] (dsl-hkibrasgw2-ff7ac300-240.dhcp.inet.fi [88.195.122.240]) by mx.google.com with ESMTPS id k13sm396244wed.35.2010.06.11.02.42.37 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 11 Jun 2010 02:42:37 -0700 (PDT) Message-ID: <4C12050A.5060100@enterprisedb.com> Date: Fri, 11 Jun 2010 12:42:34 +0300 From: Heikki Linnakangas Organization: EnterpriseDB User-Agent: Mozilla/5.0 (X11; U; Linux i686; fi-FI; rv:1.9.1.9) Gecko/20100515 Iceowl/1.0b1 Icedove/3.0.4 MIME-Version: 1.0 To: David Jarvis CC: pgsql-performance@postgresql.org Subject: Re: Analysis Function References: <4C119B3E.3090608@squeakycode.net> In-Reply-To: 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=-4.2 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3 X-Spam-Level: X-Archive-Number: 201006/203 X-Sequence-Number: 39059 On 11/06/10 11:25, David Jarvis wrote: > Datum dateserial (PG_FUNCTION_ARGS) { > int32 p_year = PG_GETARG_INT32(0); > int32 p_month = PG_GETARG_INT32(1); > int32 p_day = PG_GETARG_INT32(2); > > DateADT d = date2j (p_year, p_month, p_day) - POSTGRES_EPOCH_JDATE; > PG_RETURN_DATEADT(d); > } > > Compiles without errors or warnings. The function is integrated as follows: > > CREATE OR REPLACE FUNCTION dateserial(integer, integer, integer) > RETURNS text AS > 'ymd.so', 'dateserial' > LANGUAGE 'c' IMMUTABLE STRICT > COST 1; > > However, when I try to use it, the database segfaults: > > select dateserial( 2007, 1, 3 ) > > Any ideas why? The C function returns a DateADT, which is a typedef for int32, but the CREATE FUNCTION statement claims that it returns 'text'. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com