Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHZL5-0002Ox-9G for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Nov 2017 18:01:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHZL4-00070s-DS for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Nov 2017 18:01:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eHZL4-00070g-0K for pgsql-hackers@lists.postgresql.org; Wed, 22 Nov 2017 18:01:34 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eHZKv-00025d-14 for pgsql-hackers@postgresql.org; Wed, 22 Nov 2017 18:01:33 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 8667720CAA; Wed, 22 Nov 2017 13:01:23 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Wed, 22 Nov 2017 13:01:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=xk642A ZZvZgXFjY9jw+/JO8cnoOZboTIVnEzVmZhLYk=; b=sXTFz0Z67rYEcouJu9XPUA LbQ1vSAdgRBNL9B6DqIwEV3VbAFy1FczvcNApppSnc32dwnCu2Yg8wBb/d7UJuuh 2OmILCx451njfghL31wfuqcWXW2njmvMmejRvdrop4u4VcKkvZUz/xkgDbbbdRGb YZgPY1S11uEDilw2xmDwwgn27DPII05vo2Iz2lHBzkOJK3BDlH+vEwQDCNMWdfVz KZmfkn2rSDvAqCmsB+nY+peekjuer/Rb0qM4NXPfUDU7LRfkjYDpl+QTFr0vUgNv n4npCUXvsRLJWV18QzWsGrOm4MqWodhzMMglYqgSZ92Qe5GVHTr9e2Y5d1/Kd/8g == X-ME-Sender: Received: from [192.168.1.89] (75-58-3-122.lightspeed.tukrga.sbcglobal.net [75.58.3.122]) by mail.messagingengine.com (Postfix) with ESMTPA id 160897E8B7; Wed, 22 Nov 2017 13:01:23 -0500 (EST) Subject: Re: [HACKERS] SQL procedures To: Andrew Dunstan , pgsql-hackers References: <336f6926-8990-ff2d-4167-276ce417fc32@2ndquadrant.com> <492a8be0-ff55-3858-7dc1-62fa07d444c2@2ndquadrant.com> <6fbe425b-0b9b-0b3f-c5bb-5a5111514867@2ndquadrant.com> Cc: Simon Riggs From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <67fa3f8d-7203-702b-40a3-514eba7e1c05@2ndquadrant.com> Date: Wed, 22 Nov 2017 13:01:22 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/20/17 16:25, Andrew Dunstan wrote: > I've been through this fairly closely, and I think it's pretty much > committable. The only big item that stands out for me is the issue of > OUT parameters. I figured that that's something that would come up. I had intentionally prohibited OUT parameters for now so that we can come up with something for them without having to break any backward compatibility. From reading some of the references so far, I think it could be sufficient to return a one-row result set and have the drivers adapt the returned data into their interfaces. The only thing that would be a bit weird about that is that a CALL command with OUT parameters would return a result set and a CALL command without any OUT parameters would return CommandComplete instead. Maybe that's OK. > Default Privileges docs: although FUNCTIONS and ROUTINES are equivalent > here, we should probably advise using ROUTINES, as FUNCTIONS could > easily be take to mean "functions but not procedures". OK, I'll update the documentation a bit more. > CREATE/ALTER PROCEDURE: It seems more than a little odd to allow > attributes that are irrelevant to procedures in these statements. The > docco states "for compatibility with ALTER FUNCTION" but why do we want > such compatibility if it's meaningless? If we can manage it without too > much violence I'd prefer to see an exception raised if these are used. We can easily be more restrictive here. I'm open to suggestions. There is a difference between options that don't make sense for procedures (e.g., RETURNS NULL ON NULL INPUT), which are prohibited, and those that might make sense sometime, but are currently not used. But maybe that's too confusing and we should just prohibit options that are not currently used. > In create_function.sgml, we have: > >     If a schema name is included, then the function is created in the >     specified schema.  Otherwise it is created in the current schema. > -   The name of the new function must not match any existing function > +   The name of the new function must not match any existing > function or procedure >     with the same input argument types in the same schema.  However, >     functions of different argument types can share a name (this is >     called overloading). > > The last sentence should probably say "functions and procedures of > different argument types" There's a similar issue in create_procedure.sqml. fixing that > In grant.sgml, there is: > > +       The FUNCTION syntax also works for aggregate > +       functions.  Or use ROUTINE to refer to a > function, > +       aggregate function, or procedure regardless of what it is. > > > I would replace "Or" by "Alternatively,". I think it reads better that way. fixing that > In functions.c, there is: > >             /* Should only get here for VOID functions */ > -           Assert(fcache->rettype == VOIDOID); > +           Assert(fcache->rettype == InvalidOid || fcache->rettype > == VOIDOID); >             fcinfo->isnull = true; >             result = (Datum) 0; > > The comment should also refer to procedures. fixing that > It took me a minute to work out what is going on with the new code in > aclchk.c:objectsInSchemaToOids(). It probably merits a comment or two. improving that > We should document where returned values in PL procedures are ignored > (plperl, pltcl) and where they are not (plpython, plpgsql). Maybe we > should think about possibly being more consistent here, too. Yeah, suggestions? I think it makes sense in PL/pgSQL and PL/Python to disallow return values that would end up being ignored, because the only way a return value could arise is if user code explicit calls RETURN/return. However, in Perl, the return value is the result of the last statement, so prohibiting a return value would be very inconvenient. (Don't know about Tcl.) So maybe the current behavior makes sense. Documentation is surely needed. > The context line here looks odd: > > CREATE PROCEDURE test_proc2() > LANGUAGE plpythonu > AS $$ > return 5 > $$; > CALL test_proc2(); > ERROR:  PL/Python procedure did not return None > CONTEXT:  PL/Python function "test_proc2" > > Perhaps we need to change plpython_error_callback() so that "function" > isn't hardcoded. fixing that -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services