Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 403B01337B8D for ; Tue, 15 Mar 2011 13:13:07 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 84237-01 for ; Tue, 15 Mar 2011 16:12:59 +0000 (UTC) X-Greylist: delayed 00:15:03.48555 by SQLgrey-1.7.6 Received: from TX2EHSOBE002.bigfish.com (tx2ehsobe001.messaging.microsoft.com [65.55.88.11]) by mail.postgresql.org (Postfix) with ESMTP id 168F11337B58 for ; Tue, 15 Mar 2011 13:12:59 -0300 (ADT) Received: from mail37-tx2-R.bigfish.com (10.9.14.248) by TX2EHSOBE002.bigfish.com (10.9.40.22) with Microsoft SMTP Server id 14.1.225.8; Tue, 15 Mar 2011 15:57:53 +0000 Received: from mail37-tx2 (localhost.localdomain [127.0.0.1]) by mail37-tx2-R.bigfish.com (Postfix) with ESMTP id 93D02E48146 for ; Tue, 15 Mar 2011 15:57:53 +0000 (UTC) X-SpamScore: 0 X-BigFish: VPS0(zzzz1202hzz8275dhz2fh637h668h) X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:webmail.yougov.com; RD:static-62-50-48-98.irtnet.net; EFVD:NLI Received: from mail37-tx2 (localhost.localdomain [127.0.0.1]) by mail37-tx2 (MessageSwitch) id 1300204672734539_30975; Tue, 15 Mar 2011 15:57:52 +0000 (UTC) Received: from TX2EHSMHS043.bigfish.com (unknown [10.9.14.254]) by mail37-tx2.bigfish.com (Postfix) with ESMTP id B0B31718052 for ; Tue, 15 Mar 2011 15:57:52 +0000 (UTC) Received: from webmail.yougov.com (62.50.48.98) by TX2EHSMHS043.bigfish.com (10.9.99.143) with Microsoft SMTP Server id 14.1.225.8; Tue, 15 Mar 2011 15:57:52 +0000 Received: from [172.24.96.127] (67.211.6.10) by webmail.yougov.com (172.16.0.5) with Microsoft SMTP Server (TLS) id 8.3.83.0; Tue, 15 Mar 2011 16:57:49 +0100 Message-ID: <4D7F8C7A.4010209@yougov.com> Date: Tue, 15 Mar 2011 08:57:46 -0700 From: Robert Brewer User-Agent: Thunderbird 2.0.0.24 (X11/20101027) MIME-Version: 1.0 To: Subject: SELECT '(1, nan, 3)'::cube Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-OriginatorOrg: yougov.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.2 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3 X-Spam-Level: X-Archive-Number: 201103/226 X-Sequence-Number: 29736 Hi folks, I'm working on a hypercube implementation in Postgres using contrib/cube and need to insert 80,000 rows in one go from Python. Doing so with INSERT, even multiple statements in one call, is pretty slow. I've been investigating if using COPY is faster. It is, but there's a problem: some of the cubes should include 'NaN'::float. Writing: INSERT INTO foo (coords) VALUES (cube(ARRAY[1, 'nan', 3]::float[])); ...works fine. But I can't find the magic incantation to do the same thing using COPY FROM. Indeed, even SELECT chokes on this: # SELECT '(1, nan, 3)'::cube; ERROR: bad cube representation LINE 1: select '(1, nan, 3)'::cube; ^ DETAIL: syntax error at or near "n" Note that the 'cube' datatype also doesn't have a 'binary' repr, and COPY FROM exhibits the same problem with CSV as it does with text. I actually found out I could trick the parser into storing 'Inf' by just giving it a very large number, like '(1, 1e+309, 3)::cube', but I can't figure out an equivalent trick for NaN. Also note that 'nan' and 'inf' are not a problem for float[] # select '{1, nan, inf}'::float[]; float8 ----------- {1,NaN,Infinity} (1 row) ...but 1e+309 raises an error for float (where it does not for cube): # select '{1, 1e+309, 3}'::float[]; ERROR: "1e+309" is out of range for type double precision LINE 1: select '{1, 1e+309, 3}'::float[]; So: 1. It would be good to have cube parsing in PG behave more like float, allowing 'nan' and 'inf', and once those are working, deny using large numbers to fake the parser into returning Infinity. 2. If anyone can think of a way to trick the cube parser in the short term into returning NaN, I'd love to hear it. 3. If anyone understands cubeparse.c better than I do and can shoot me a quick patch, I'd appreciate it. Robert Brewer fumanchu@aminus.org