pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexey Bashtanov <bashtanov@imap.cc>
To: pgsql-bugs@postgresql.org
Subject: set/reset issues in create function and set_config
Date: Tue, 24 Apr 2018 16:32:08 +0100
Message-ID: <a7c1f0cb-1031-abf8-e4cc-13cf781d6563@imap.cc> (raw)

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 
<https://www.postgresql.org/docs/9.4/static/sql-createfunction.html;), 
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

Attachments: download all (2 files, .tar.gz)

disallow-create-function-set-default.patch (text/x-patch, 2.4K) download 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));
document-set_config-2nd-null.patch (text/x-patch, 1.0K) download 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 **** <para> <function>set_config</function> sets the parameter <parameter>setting_name</parameter> to ! <parameter>new_value</parameter>. If <parameter>is_local</parameter> is <literal>true</literal>, 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 ---- <para> <function>set_config</function> sets the parameter <parameter>setting_name</parameter> to ! <parameter>new_value</parameter>. If <parameter>new_value</parameter> ! is null the value is reset to default. If <parameter>is_local</parameter> is <literal>true</literal>, the new value will only apply to the current transaction. If you want the new value to apply for the current session, use

view thread (2+ messages)  latest in thread

Message-ID: <a7c1f0cb-1031-abf8-e4cc-13cf781d6563@imap.cc>
Permalink:  ../a7c1f0cb-1031-abf8-e4cc-13cf781d6563@imap.cc/
Also on:    postgresql.org/message-id/a7c1f0cb-1031-abf8-e4cc-13cf781d6563@imap.cc

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: bashtanov@imap.cc
  Subject: Re: set/reset issues in create function and set_config
  In-Reply-To: <a7c1f0cb-1031-abf8-e4cc-13cf781d6563@imap.cc>
  References: <a7c1f0cb-1031-abf8-e4cc-13cf781d6563@imap.cc>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox