pg_get_functiondef() does not show LEAKPROOF for leakproof functions

Started by Jeevan Chalkeover 10 years ago3 messages
#1Jeevan Chalke
jeevan.chalke@enterprisedb.com
1 attachment(s)

Hi,

If function is created with the LEAKPROOF option, then pg_get_functiondef()
does not show that in the returned definition.
Is it expected OR are we missing that option in pg_get_functiondef().

However only superuser can define a leakproof function.
Was this the reson we are not showing that in pg_get_functiondef() output?

I don't think we should hide this detail.

Here is the sample testcase to reproduce the issue:

postgres=# CREATE OR REPLACE FUNCTION foobar(i integer) RETURNS integer AS
$$
BEGIN
RETURN i + 1;
END;
$$
STRICT
LEAKPROOF
LANGUAGE plpgsql;
CREATE FUNCTION
postgres=# select pg_get_functiondef((select oid from pg_proc where proname
= 'foobar'));
pg_get_functiondef
-----------------------------------------------------
CREATE OR REPLACE FUNCTION public.foobar(i integer)+
RETURNS integer +
LANGUAGE plpgsql +
STRICT +
AS $function$ +
BEGIN +
RETURN i + 1; +
END; +
$function$ +

(1 row)

postgres=# select proname, proleakproof from pg_proc where proname =
'foobar';
proname | proleakproof
---------+--------------
foobar | t
(1 row)

Attached patch which adds that in pg_get_functiondef().

--
Jeevan B Chalke
Principal Software Engineer, Product Development
EnterpriseDB Corporation
The Enterprise PostgreSQL Company

Attachments:

fix_leakproof_in_pg_get_functiondef.patchtext/x-patch; charset=US-ASCII; name=fix_leakproof_in_pg_get_functiondef.patchDownload
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 5517113..e316951 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1985,6 +1985,8 @@ pg_get_functiondef(PG_FUNCTION_ARGS)
 		appendStringInfoString(&buf, " STRICT");
 	if (proc->prosecdef)
 		appendStringInfoString(&buf, " SECURITY DEFINER");
+	if (proc->proleakproof)
+		appendStringInfoString(&buf, " LEAKPROOF");
 
 	/* This code for the default cost and rows should match functioncmds.c */
 	if (proc->prolang == INTERNALlanguageId ||
#2Michael Paquier
michael.paquier@gmail.com
In reply to: Jeevan Chalke (#1)
Re: pg_get_functiondef() does not show LEAKPROOF for leakproof functions

On Thu, May 28, 2015 at 5:52 PM, Jeevan Chalke
<jeevan.chalke@enterprisedb.com> wrote:

If function is created with the LEAKPROOF option, then pg_get_functiondef()
does not show that in the returned definition.
Is it expected OR are we missing that option in pg_get_functiondef().

However only superuser can define a leakproof function.
Was this the reason we are not showing that in pg_get_functiondef() output?>
I don't think we should hide this detail.

Agreed. I guess that it has been simply forgotten. pg_proc can be
easily queried, so functions marked as leakproof are easy to find out
in any case.
--
Michael

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

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Paquier (#2)
Re: pg_get_functiondef() does not show LEAKPROOF for leakproof functions

Michael Paquier <michael.paquier@gmail.com> writes:

On Thu, May 28, 2015 at 5:52 PM, Jeevan Chalke
<jeevan.chalke@enterprisedb.com> wrote:

If function is created with the LEAKPROOF option, then pg_get_functiondef()
does not show that in the returned definition.
Is it expected OR are we missing that option in pg_get_functiondef().

Agreed. I guess that it has been simply forgotten. pg_proc can be
easily queried, so functions marked as leakproof are easy to find out
in any case.

Looks like a clear oversight to me. I had first thought that this might
have been intentional because pg_dump needed it to act like that --- but
pg_dump doesn't use pg_get_functiondef. I think it was simply forgotten.

regards, tom lane

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