From ruby-pg at j-davis.com Fri Nov 16 18:54:25 2007 From: ruby-pg at j-davis.com (Jeff Davis) Date: Fri, 16 Nov 2007 15:54:25 -0800 Subject: [Ruby-pg-general] ruby postgresql question In-Reply-To: References: <2F2B2C51-4359-436F-AFB2-B3A94E860248@vpop.net> <1193865048.22428.8.camel@dogma.ljc.laika.com> Message-ID: <1195257265.22428.248.camel@dogma.ljc.laika.com> On Wed, 2007-10-31 at 15:09 -0700, Brad Hilton wrote: > Basically, it uses scanf to parse time, date, and timestamp columns > rather than relying on the very slow Date.parse and Time.parse > functions. This code will only work with the ISO DateStyle and YMD > DateOrder, but postgresql treats those as the defaults. If there were > a fast, effecient way to query those values from within the library, > we could support other values there. This speads up queries with date > and time based columns dramatically. > Hi, I apologize for the delay in review of your patch. I am copying the ruby-pg list, please let's move the discussion there. You are using sscanf() to parse the time. One of the format strings you are using is: "%04d-%02d-%02d %02d:%02d:%02d.%d%03d" where "%d" is the usecs. However, if the input to sscanf is "... 01:01:01.1", clearly that's 100000 usec, not 1 usec. What do you think about trying to obtain the results in binary for translation purposes instead? I think the whole translation concept makes more sense when getting the results in binary, particularly for types that can take on many text representations for output of the same value (like timestamps). If not, let's at least try to make all the parsing code as easy to maintain as possible (and correct). I'd like to split all the translation code into another file if possible. Regards, Jeff Davis