X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C503AD89C3 for ; Thu, 8 Sep 2005 16:37:50 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 04918-06 for ; Thu, 8 Sep 2005 19:37:47 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 3D23CD89AA for ; Thu, 8 Sep 2005 16:37:47 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j88JbiAE037812 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 8 Sep 2005 13:37:47 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j88Jbikb083915; Thu, 8 Sep 2005 13:37:44 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j88JbiLc083914; Thu, 8 Sep 2005 13:37:44 -0600 (MDT) (envelope-from mfuhr) Date: Thu, 8 Sep 2005 13:37:43 -0600 From: Michael Fuhr To: Norman Yamada Cc: pgsql-interfaces@postgresql.org, Yasser El-Zein Subject: Re: getting julian number from date in libpq Message-ID: <20050908193743.GA83658@winnie.fuhr.org> References: <7D1583CD-3DEC-4F01-BF07-6599B7AEF38B@millburncorp.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7D1583CD-3DEC-4F01-BF07-6599B7AEF38B@millburncorp.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 required=5 tests=[AWL=0.005] X-Spam-Level: X-Archive-Number: 200509/5 X-Sequence-Number: 5728 On Thu, Sep 08, 2005 at 02:12:33PM -0400, Norman Yamada wrote: > We're trying to convert dates properly for R. > > R stores dates internally as integers, using Unix date style -- > starting date is January 1, 1970. > > Postgresql stores dates as Julian days, but using libpq, I don't see > how to get out a date quickly as a julian day. If I use PQgetvalue, > my date is automagically converted into whatever my DATESTYLE is at > the time. How can I just get out the internal julian date? In 7.4 and later you could use PQexecParams() to request binary results; in earlier versions you could use a binary cursor. But the result will be days since 1 Jan 2000, not 1 Jan 1970, so you'd have to do a conversion; you'd also have to convert the binary value from network byte order to host byte order. It might be easier to use the date subtraction operator: SELECT current_date - '1970-01-01'; ?column? ---------- 13034 (1 row) -- Michael Fuhr