Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fAzvu-0002BZ-Sk for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Apr 2018 15:32:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fAzvt-0007S2-RI for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Apr 2018 15:32:41 +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.89) (envelope-from ) id 1fAzvr-0007Rj-Uc for pgsql-bugs@lists.postgresql.org; Tue, 24 Apr 2018 15:32:41 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fAzvm-0000ij-MV for pgsql-bugs@postgresql.org; Tue, 24 Apr 2018 15:32:39 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 84F7321C87 for ; Tue, 24 Apr 2018 11:32:32 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 24 Apr 2018 11:32:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=imap.cc; h= content-type:date:from:message-id:mime-version:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=cBvl3mzerW+F5mGie USNAiEG+Noy2aSCUAva0dqIto4=; b=wS3PicZNGb3WpSENGjF/KAX2drv6o3DKm 34FfZR5BrBviUh+3f4ckey7WzGeYqWF9yd9vNg/9eWjRekrF3oZVg0bN7p7Pbu2Q li8zHhMYlAr/bBge97aKyrr6JqOJ4xVd7z3sGteLXsV5jZTuggb53rzvcH3Hfjr/ GbPzclzJ7R9XyCGhbLTvj7CuGd1Sql00Kilvtnci4WzEZ2+39gd58ziTi6IUODcq Uw8J1Px7upxxncwSFEm6WKui1ob4WA0OPdQmdUAqg2i2JRvbFQXWMiJfJ5SbfvNb c0DDCg1G+85tvy/S7WvE38yOosvtscLkKbdquahcsOLGSJspqTHZQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=cBvl3mzerW+F5mGieUSNAiEG+Noy2aSCUAva0dqIto4=; b=VzJl6++8 Z233pPn/t13j/omcjGbJBdX2kYfd0h5W2CL2isWM+VCw7dQJo8bVsj7Z2Oc05K9Q Y9FHFa/ZdzqYNMh0h3AeH5UEpIzsTtD9fkF8NJQA1sUrQepY+1sNRA929TvYJ4wQ Onxl686+mc8yUTXMJYVHGYzEycAveVjgluYt4I424NCuYxYjCg2dYKK6wXurJU3J /7mUj8rLkBrknqODobfJ5cZyS/ycAY4mPMTvIU/JinmvVT1bq+8ZY6ghyFrm+/6A Ji7lbfuiWskQYKd6rjCVzBVac5uaXLZzicZZzNpMNqZ1yoJBkuJtXeqQvgUdW/U8 g6Aj48g8qc0fwA== X-ME-Sender: Received: from [10.2.33.124] (unknown [185.25.33.70]) by mail.messagingengine.com (Postfix) with ESMTPA id 0B3CD1025C for ; Tue, 24 Apr 2018 11:32:31 -0400 (EDT) To: pgsql-bugs@postgresql.org From: Alexey Bashtanov Subject: set/reset issues in create function and set_config Message-ID: Date: Tue, 24 Apr 2018 16:32:08 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------709663B13338F33FBB41DFC7" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------709663B13338F33FBB41DFC7 Content-Type: multipart/alternative; boundary="------------8E5B5E2CF2024A2E342E8A0A" --------------8E5B5E2CF2024A2E342E8A0A Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hello, It looks like set_config does set-to-default if it's called with second argument being null, but this is undocumented. Please see the docs patch to fix it. Also, SET to DEFAULT or RESET in CREATE FUNCTION is accepted but does nothing. It wouldn't be a problem, but documentation to SET command says: > If SET LOCAL is used within a function that has a SET option for the same variable (see CREATE FUNCTION ), the effects of the SET LOCAL command disappear at function exit This doesn't work with CREATE FUNCTION ... SET ... DEFAULT .... What do you think of just disallowing it? Patch attached as well. Best regards,   Alexey --------------8E5B5E2CF2024A2E342E8A0A Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit Hello,

It looks like set_config does set-to-default if it's called with second argument being null, but this is undocumented.
Please see the docs patch to fix it.

Also, SET to DEFAULT or RESET in CREATE FUNCTION is accepted but does nothing.
It wouldn't be a problem, but documentation to SET command says:

> If SET LOCAL is used within a function that has a SET option for the same variable (see CREATE FUNCTION), the effects of the SET LOCAL command disappear at function exit

This doesn't work with CREATE FUNCTION ... SET ... DEFAULT ....
What do you think of just disallowing it? Patch attached as well.

Best regards,
  Alexey
--------------8E5B5E2CF2024A2E342E8A0A-- --------------709663B13338F33FBB41DFC7 Content-Type: text/x-patch; name="disallow-create-function-set-default.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="disallow-create-function-set-default.patch" diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c new file mode 100644 index 3c74873..e8c2a34 *** a/src/backend/commands/functioncmds.c --- b/src/backend/commands/functioncmds.c *************** interpret_func_parallel(DefElem *defel) *** 610,616 **** * The input and result may be NULL to signify a null entry. */ static ArrayType * ! update_proconfig_value(ArrayType *a, List *set_items) { ListCell *l; --- 610,616 ---- * The input and result may be NULL to signify a null entry. */ static ArrayType * ! update_proconfig_value(ArrayType *a, List *set_items, bool allow_reset) { ListCell *l; *************** update_proconfig_value(ArrayType *a, Lis *** 626,633 **** if (valuestr) a = GUCArrayAdd(a, sstmt->name, valuestr); ! else /* RESET */ ! a = GUCArrayDelete(a, sstmt->name); } } --- 626,640 ---- if (valuestr) a = GUCArrayAdd(a, sstmt->name, valuestr); ! else ! if (allow_reset) /* RESET */ ! a = GUCArrayDelete(a, sstmt->name); ! else { ! ereport(ERROR, ! (errcode(ERRCODE_SYNTAX_ERROR), ! errmsg("Cannot RESET or SET to DEFAULT when creating a function or a procedure"))); ! return NULL; /* keep compiler quiet */ ! } } } *************** compute_function_attributes(ParseState * *** 770,776 **** if (leakproof_item) *leakproof_p = intVal(leakproof_item->arg); if (set_items) ! *proconfig = update_proconfig_value(NULL, set_items); if (cost_item) { *procost = defGetNumeric(cost_item); --- 777,783 ---- if (leakproof_item) *leakproof_p = intVal(leakproof_item->arg); if (set_items) ! *proconfig = update_proconfig_value(NULL, set_items, false); if (cost_item) { *procost = defGetNumeric(cost_item); *************** AlterFunction(ParseState *pstate, AlterF *** 1279,1285 **** a = isnull ? NULL : DatumGetArrayTypeP(datum); /* update according to each SET or RESET item, left to right */ ! a = update_proconfig_value(a, set_items); /* update the tuple */ memset(repl_repl, false, sizeof(repl_repl)); --- 1286,1292 ---- a = isnull ? NULL : DatumGetArrayTypeP(datum); /* update according to each SET or RESET item, left to right */ ! a = update_proconfig_value(a, set_items, true); /* update the tuple */ memset(repl_repl, false, sizeof(repl_repl)); --------------709663B13338F33FBB41DFC7 Content-Type: text/x-patch; name="document-set_config-2nd-null.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="document-set_config-2nd-null.patch" diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml new file mode 100644 index 53a40dd..e79d21a *** a/doc/src/sgml/func.sgml --- b/doc/src/sgml/func.sgml *************** SELECT current_setting('datestyle'); *** 18480,18486 **** set_config sets the parameter setting_name to ! new_value. If is_local is true, the new value will only apply to the current transaction. If you want the new value to apply for the current session, use --- 18480,18487 ---- set_config sets the parameter setting_name to ! new_value. If new_value ! is null the value is reset to default. If is_local is true, the new value will only apply to the current transaction. If you want the new value to apply for the current session, use --------------709663B13338F33FBB41DFC7--