Re: [HACKERS] Improvements in psql hooks for variables - Mailing list pgsql-hackers

From Daniel Verite
Subject Re: [HACKERS] Improvements in psql hooks for variables
Date
Msg-id d1e8b35d-32a7-4722-b98f-e1db46b90777@manitou-mail.org
Whole thread Raw
In response to Re: [HACKERS] Improvements in psql hooks for variables  ("Daniel Verite" <daniel@manitou-mail.org>)
Responses Re: [HACKERS] Improvements in psql hooks for variables  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
    I wrote:

> This would allow the hook to distinguish between initialization and
> unsetting, which in turn will allow it to deny the \unset in the
> cases when it doesn't make any sense conceptually (like AUTOCOMMIT).

I notice that in the commited patch, you added the ability
for DeleteVariable() to reject the deletion if the hook
disagrees.
+            {
+                /* Allow deletion only if hook is okay with
NULL value */
+                if (!(*current->assign_hook) (NULL))
+                    return false;        /* message
printed by hook */

But this can't happen in practice because as mentioned just upthread
the hook called with NULL doesn't know if the variable is getting unset
or initialized, so rejecting on NULL is not an option.

Attached is a proposed patch to add initial values to
SetVariableAssignHook() to solve this problem, and an example for
\unset AUTOCOMMIT being denied by the hook.

As a side effect, we see all buit-in variables when issuing \set
rather than just a few.

Does it make sense?

Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachment

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: [HACKERS] Patch: Write Amplification Reduction Method (WARM)
Next
From: Corey Huinker
Date:
Subject: Re: \if, \elseif, \else, \endif (was Re: [HACKERS] PSQL commands:\quit_if, \quit_unless)