Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id EDE76B5DBC7 for ; Fri, 7 Oct 2011 07:21:47 -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 24169-10 for ; Fri, 7 Oct 2011 10:21:41 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail-ey0-f174.google.com (mail-ey0-f174.google.com [209.85.215.174]) by mail.postgresql.org (Postfix) with ESMTP id 22758B5DBC4 for ; Fri, 7 Oct 2011 07:21:40 -0300 (ADT) Received: by eyg7 with SMTP id 7so956270eyg.19 for ; Fri, 07 Oct 2011 03:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=iOhH1GefY+xxv3DDoIuw+dupFLGcMnofRLAoI2/C1tE=; b=lZuCXKJde/TSauLNKc5PO1YI0mkDdJlnIQ39/Bvqp1pUkckskNvm8owDkan6nU+O0z X4PFZ1AhWRlIxzXSpspmQsOM9sg4GuphfBZEUk+MRu3JXE5/5HnUOHNN2IIawhLQh/6d sbo1eilJVkmkd80a8HocByzJUQTa+TBAxzCCI= Received: by 10.14.15.77 with SMTP id e53mr277774eee.63.1317982900079; Fri, 07 Oct 2011 03:21:40 -0700 (PDT) Received: from [192.168.73.63] (5357DA75.cm-6-8d.dynamic.ziggo.nl. [83.87.218.117]) by mx.google.com with ESMTPS id u11sm13904175eeb.2.2011.10.07.03.21.39 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 07 Oct 2011 03:21:39 -0700 (PDT) Message-ID: <4E8ED2A7.2040800@gmail.com> Date: Fri, 07 Oct 2011 12:21:27 +0200 From: Yeb Havinga User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: Royce Ausburn CC: Pg Hackers Subject: Re: [REVIEW] Patch for cursor calling with named parameters References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201110/360 X-Sequence-Number: 196166 On 2011-10-06 16:04, Royce Ausburn wrote: > Initial Review for patch: > > http://archives.postgresql.org/pgsql-hackers/2011-09/msg00744.php Hello Royce, Thank you for your review. > > I don't think so. The new feature accepts opening a cursor with some > parameter names not specified: > > open cur1(param3 := 4, 1, param1 := 5); > > It seems that if a parameter is not named, its position is used to > bind to a variable. For example, the following fail: > > psql:plsqltest.sql:26: ERROR: cursor "cur1" argument 2 "param2" > provided multiple times > LINE 10: open cur1(param3 := 4, 1, param2 := 5); > > and > > psql:plsqltest.sql:26: ERROR: cursor "cur1" argument 2 "param2" > provided multiple times > LINE 10: open cur1(param2 := 4, 2, param1 := 5); > > > I think that postgres ought to enforce some consistency here. Use one > way or the other, never both. This was meant as a feature, but I can remove it. > > > I can also produce some unhelpful errors when I give bad syntax. For > example: > > psql:plsqltest.sql:28: ERROR: cursor "cur1" argument 1 "param1" > provided multiple times > LINE 11: open cur1( param3 : = 4, 2, param1 := 5); > (notice the space between the : and =) Yes, the whole of the expression before the first comma, 'param3 : = 4' is not recognized as <:= symbol> , so that is taken as the value of the first parameter. This value is parsed after all named arguments are read, and hence no meaningful error is given. If there was no param1 parameter name at the end, the 'multiple times' error would not have caused the processing to stop, and a syntax error at the correct : would have been given. The same reasoning also explains the other 'multiple times' errors you could get, by putting a syntax error in some value. > > -- > > open cur1( param3 := param3 , param2 = 3, param1 := 1 ); > > psql:plsqltest.sql:29: ERROR: column "param2" does not exist > LINE 2: ,param2 = 3 > ^ > QUERY: SELECT 1 > ,param2 = 3 > ,param3; > CONTEXT: PL/pgSQL function "named_para_test" line 7 at OPEN This is a valid error, since the parser / SQL will try to evaluate the boolean expression param2 = 3, while param2 is not a defined variabele. Again, thank you very much for your thorough review. I'll update the patch so mixing positional and named parameters are removed, add documentation, and give syntax errors before an error message indicating that positional and named parameters were mixed. -- Yeb Havinga http://www.mgrid.net/ Mastering Medical Data