Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 90B34358049 for ; Sat, 28 Apr 2012 20:20:45 -0300 (ADT) Received: from mail-qa0-f46.google.com ([209.85.216.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SOGwW-0007fw-Gr for pgsql-bugs@postgresql.org; Sat, 28 Apr 2012 23:20:45 +0000 Received: by qatm19 with SMTP id m19so926308qat.19 for ; Sat, 28 Apr 2012 16:20:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=06eHVKRb6JZ5/TongBlfQ1W99k6M1DxTUr5jMQFkh48=; b=RCJati49BQixHtiBejavSrCB8psjY9hlxv/1WwAHX8xiYtr90L/kswegsmdR8gd+za /NTHOSazii0dhKWp6smBr2TmUm8KGkvnhfyAGyTJYTVXFxD6PyFwC1Wh/48Kat4QBJvs G7i28nMDDNBjPlpDpMxieS0+kKkVPAkMl6oMsxDx06TJI8UQnZaz9OjoLbQXJQtsWGFx z7uBzcMH+HR7i5tqrcBGfeH/g1fu+x6z8jrjTuSkR/E5XCWdp/M7RhAemQTNyk74q8lB +nBqx5H8xTHYjhZbkPqGPFEWd3d5JLAgIhM14pIVfSsr2HldSIGo2w3FrExvu1Xd6PTi jUOw== Received: by 10.229.135.208 with SMTP id o16mr4008291qct.120.1335655230745; Sat, 28 Apr 2012 16:20:30 -0700 (PDT) Received: from llserver.lakeliving.com (ool-18bbd2c6.static.optonline.net. [24.187.210.198]) by mx.google.com with ESMTPS id hs1sm2571282qab.21.2012.04.28.16.20.28 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 28 Apr 2012 16:20:29 -0700 (PDT) Date: Sat, 28 Apr 2012 19:20:25 -0400 From: Ryan Kelly To: Tom Lane Cc: Vik Reykja , pgsql-bugs@postgresql.org Subject: Re: hstore parser incorrectly handles malformed input Message-ID: <20120428232025.GA10175@llserver.lakeliving.com> References: <20120426190513.GB31886@llserver.lakeliving.com> <12884.1335469833@sss.pgh.pa.us> <19224.1335489137@sss.pgh.pa.us> <20120427112235.GA9024@llserver.lakeliving.com> <19559.1335536531@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <19559.1335536531@sss.pgh.pa.us> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.3 (--) X-Archive-Number: 201204/212 X-Sequence-Number: 32963 On Fri, Apr 27, 2012 at 10:22:11AM -0400, Tom Lane wrote: > Ryan Kelly writes: > > As long as we make it consistent on both sides of the '=>' (and document > > it, too), then I don't really care either way. Currently you have to use > > quotes to get an empty key, so I thought it natural to that you should > > have to quote to get an empty value. > > > I've attached a modified version of Tom's patch which also allows empty > > keys. > > Hm ... I don't agree that keys and values are interchangeable, and > I don't see that empty keys are a good thing (whereas empty values are > clearly a reasonable edge case). So I think this is going a bit far; > it seems to me it'd be giving up a lot of syntax-error detection > capability in return for some not-actually-helpful symmetry. I don't think any language supports the empty key edge case in this way. The only language I know of that will let you get away with it is Perl, and in that case you get undef, not the empty string, and it's a warning if you have warnings on: $ use warnings; $ my $h = { 1 => }; Odd number of elements in anonymous hash $HASH1 = { 1 => undef }; In fact, it's akin to doing: [db]> select hstore('{foo}'::text[]); ERROR: array must have even number of elements Or maybe even this: [db]> select hstore('{foo,}'::text[]); ERROR: malformed array literal: "{foo,}" Python: >>> h = {1 : } SyntaxError: invalid syntax Ruby: >> h = {1 => } SyntaxError: compile error C#: csharp> var h = new Dictionary(){ { "1", } }; {interactive}(1,50): error CS1525: Unexpected symbol `}' csharp> var h = new Dictionary(){ { "1" } }; {interactive}(1,44): error CS1501: No overload for method `Add' takes `1' arguments JavaScript: js> a = { 1: } typein:1: SyntaxError: syntax error: PHP: $ echo ' ); ?>' | php PHP Parse error: syntax error, unexpected ')' > On the other hand, I seldom use hstore so I'm probably not the best > person to be judging the appropriateness of these options. Any other > votes out there? As long as we're voting, I vote for my original patch. I think requiring something on the RHS of => to get a value is a sane and rather common thing. > > regards, tom lane -Ryan Kelly