pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feed"create function... depends on extension..." not supported. Why?
7+ messages / 4 participants
[nested] [flat]
* "create function... depends on extension..." not supported. Why?
@ 2022-04-27 00:22 Bryn Llewellyn <bryn@yugabyte.com>
0 siblings, 1 reply; 7+ messages in thread
From: Bryn Llewellyn @ 2022-04-27 00:22 UTC (permalink / raw)
To: pgsql-general list <pgsql-general@lists.postgresql.org>
Note: I’m asking because the answer to the question “Why isn’t X supported?” is always useful. For example, if supporting it would imply a logical impossibility that I’m too slow to spot, it helps me when someone explains what I failed to realize. Equally, it helps me to know when the answer is “It’s just a historical accident. It could have been supported. But, now that it isn’t, it doesn’t seem worth the effort to bridge that gap” because this shows me that my existing mental model is sound.
The background for my question here is that among the documented changes that you can make using “alter function”
https://www.postgresql.org/docs/current/sql-alterfunction.html
you can specify all of them at “create time” too (but possibly, like “owner”, only implicitly) except for “depends on extension”. When you know in advance that you want to set this property, you need two statements:
create function f()
returns int
language plpgsql
as $body$
begin
return 42;
end;
$body$;
alter function f()
depends on extension pgcrypto;
Why is this not supported:
create function f()
returns int
language plpgsql
depends on extension pgcrypto
as $body$
begin
return 42;
end;
$body$;
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: "create function... depends on extension..." not supported. Why?
@ 2022-04-27 00:44 David G. Johnston <david.g.johnston@gmail.com>
parent: Bryn Llewellyn <bryn@yugabyte.com>
0 siblings, 1 reply; 7+ messages in thread
From: David G. Johnston @ 2022-04-27 00:44 UTC (permalink / raw)
To: Bryn Llewellyn <bryn@yugabyte.com>; +Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
On Tue, Apr 26, 2022 at 5:22 PM Bryn Llewellyn <bryn@yugabyte.com> wrote:
> Note: I’m asking because the answer to the question “Why isn’t X
> supported?” is always useful. For example, if supporting it would imply a
> logical impossibility that I’m too slow to spot, it helps me when someone
> explains what I failed to realize. Equally, it helps me to know when the
> answer is “It’s just a historical accident. It could have been supported.
> But, now that it isn’t, it doesn’t seem worth the effort to bridge that
> gap” because this shows me that my existing mental model is sound.
>
Here is the commit that brought the feature into existence (it includes a
link to the archives for discussion from which you can read or infer
things).
https://github.com/postgres/postgres/commit/f2fcad27d59c8e5c48f8fa0a96c8355e40f24273
David J.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: "create function... depends on extension..." not supported. Why?
@ 2022-04-27 01:20 Bryn Llewellyn <bryn@yugabyte.com>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Bryn Llewellyn @ 2022-04-27 01:20 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
> david.g.johnston@gmail.com wrote:
>
>> bryn@yugabyte.com wrote:
>>
>> Note: I’m asking because the answer to the question “Why isn’t X supported?” is always useful. For example, if supporting it would imply a logical impossibility that I’m too slow to spot, it helps me when someone explains what I failed to realize. Equally, it helps me to know when the answer is “It’s just a historical accident. It could have been supported. But, now that it isn’t, it doesn’t seem worth the effort to bridge that gap” because this shows me that my existing mental model is sound.
>
> Here is the commit that brought the feature into existence (it includes a link to the archives for discussion from which you can read or infer things).
>
> https://github.com/postgres/postgres/commit/f2fcad27d59c8e5c48f8fa0a96c8355e40f24273
The discussion has diverging threads and very many turns. I think that I managed to skim through the entire tree. As I read it, the discussion was entirely about the semantics of the proposed dependency of a function (or procedure) upon an extension. The idea to establish such a dependency using “alter function” came up quite early in the discussion. It seems that establishing it at “create function” time was never considered.
Unless anybody corrects me, I’ll conclude that it’s perfectly feasible to establish the dependency at “create function” time. This would meet an obvious niceness goal (symmetry and guessability). It would also increase the possibility for component rule re-use in the presentation of the syntax rules. But I don’t s’pose that the effort of changing anything here would be cost-effective.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: "create function... depends on extension..." not supported. Why?
@ 2022-04-27 01:31 Tom Lane <tgl@sss.pgh.pa.us>
parent: Bryn Llewellyn <bryn@yugabyte.com>
0 siblings, 2 replies; 7+ messages in thread
From: Tom Lane @ 2022-04-27 01:31 UTC (permalink / raw)
To: Bryn Llewellyn <bryn@yugabyte.com>; +Cc: David G. Johnston <david.g.johnston@gmail.com>; pgsql-general list <pgsql-general@lists.postgresql.org>
Bryn Llewellyn <bryn@yugabyte.com> writes:
> The discussion has diverging threads and very many turns. I think that I managed to skim through the entire tree. As I read it, the discussion was entirely about the semantics of the proposed dependency of a function (or procedure) upon an extension. The idea to establish such a dependency using “alter function” came up quite early in the discussion. It seems that establishing it at “create function” time was never considered.
Probably not. Just for the record, it's not true that CREATE and ALTER
always have the same set of options. An obvious counterexample is that
you can't set the owner to someone different from yourself during CREATE.
There may be others.
I suppose that "DEPENDS ON EXTENSION" was modeled after the commands
to control extension membership, which likewise exist only in ALTER
form because CREATE's behavior for that is hard-wired. If you wanted
to hand-wave a lot, you could maybe claim that ownership and extension
membership/dependency are similar kinds of relationships and so it
makes sense that the command structures for manipulating them are
similar. But TBH that would probably be reverse-engineering an
explanation. I think that "we didn't bother" is more nearly the
situation.
regards, tom lane
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: "create function... depends on extension..." not supported. Why?
@ 2022-04-27 03:18 Bryn Llewellyn <bryn@yugabyte.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 7+ messages in thread
From: Bryn Llewellyn @ 2022-04-27 03:18 UTC (permalink / raw)
To: Tom Lane PostgreSQL <tgl@sss.pgh.pa.us>; +Cc: David G. Johnston <david.g.johnston@gmail.com>; pgsql-general list <pgsql-general@lists.postgresql.org>
> tgl@sss.pgh.pa.us wrote:
>
>> bryn@yugabyte.com wrote:
>>
>> The discussion has diverging threads and very many turns. I think that I managed to skim through the entire tree. As I read it, the discussion was entirely about the semantics of the proposed dependency of a function (or procedure) upon an extension. The idea to establish such a dependency using “alter function” came up quite early in the discussion. It seems that establishing it at “create function” time was never considered.
>
> Probably not. Just for the record, it's not true that CREATE and ALTER always have the same set of options. An obvious counterexample is that you can't set the owner to someone different from yourself during CREATE. There may be others.
>
> I suppose that "DEPENDS ON EXTENSION" was modeled after the commands to control extension membership, which likewise exist only in ALTER form because CREATE's behavior for that is hard-wired. If you wanted to hand-wave a lot, you could maybe claim that ownership and extension membership/dependency are similar kinds of relationships and so it makes sense that the command structures for manipulating them are similar. But TBH that would probably be reverse-engineering an explanation. I think that "we didn't bother" is more nearly the situation.
Thanks, Tom. Just as I’d hoped, I found your “we didn’t bother” reply very helpful. I take your point about the inevitability of some differences between what “create function” and “alter function” can express.
B.t.w., in Oracle Database, you can create a schema object with any owner as long as you have the object-type-specific “ANY” privilege. (You need an ordinary object-type-specific privilege just to create objects that you own yourself.) The PG model is as different from the Oracle model as it could be in the general area of creating, altering, and dropping schema objects. I see that “alter” to change the owner only after the fact, requiring as it does a superuser, is [almost] a forced choice in PG.
It would seem, though, that syntax could be invented to allow a superuser to create an object of any type with any owner. But I s’pose that the usability benefit that this would bring would be marginal and it might even tempt bad practices.=
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: "create function... depends on extension..." not supported. Why?
@ 2022-04-27 09:32 Alvaro Herrera <alvherre@alvh.no-ip.org>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 7+ messages in thread
From: Alvaro Herrera @ 2022-04-27 09:32 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Bryn Llewellyn <bryn@yugabyte.com>; David G. Johnston <david.g.johnston@gmail.com>; pgsql-general list <pgsql-general@lists.postgresql.org>
On 2022-Apr-26, Tom Lane wrote:
> I suppose that "DEPENDS ON EXTENSION" was modeled after the commands
> to control extension membership, which likewise exist only in ALTER
> form because CREATE's behavior for that is hard-wired. If you wanted
> to hand-wave a lot, you could maybe claim that ownership and extension
> membership/dependency are similar kinds of relationships and so it
> makes sense that the command structures for manipulating them are
> similar. But TBH that would probably be reverse-engineering an
> explanation. I think that "we didn't bother" is more nearly the
> situation.
IIRC Abhijit and I discussed this point offline, and our conclusion was
that DEPENDS ON EXTENSION was not of general enough usefulness to
warrant support for it in CREATE FUNCTION -- keeping in mind that we
would need support for it in CREATE INDEX, CREATE TRIGGER, CREATE
MATERIALIZED VIEW as well.
It's probably not that much code. The effort of writing the code wasn't
the barrier we were optimizing for, but rather for getting the whole
*idea* accepted.
If this feature is suddenly so useful as to *require* support in the
various CREATE commands, that is most satisfying to me and I volunteer
to reviewing patches that implement it.
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: "create function... depends on extension..." not supported. Why?
@ 2022-04-27 13:48 Tom Lane <tgl@sss.pgh.pa.us>
parent: Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 0 replies; 7+ messages in thread
From: Tom Lane @ 2022-04-27 13:48 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: Bryn Llewellyn <bryn@yugabyte.com>; David G. Johnston <david.g.johnston@gmail.com>; pgsql-general list <pgsql-general@lists.postgresql.org>
Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> IIRC Abhijit and I discussed this point offline, and our conclusion was
> that DEPENDS ON EXTENSION was not of general enough usefulness to
> warrant support for it in CREATE FUNCTION -- keeping in mind that we
> would need support for it in CREATE INDEX, CREATE TRIGGER, CREATE
> MATERIALIZED VIEW as well.
Yeah. Quite aside from the code bloat and grammar bloat, my main
fear about that would be the assumption that we could wedge a consistent
syntax for this into all those different sorts of CREATE commands.
At the very least we'd probably find ourselves having to make those
keywords more reserved than they are now.
regards, tom lane
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2022-04-27 13:48 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27 00:22 "create function... depends on extension..." not supported. Why? Bryn Llewellyn <bryn@yugabyte.com>
2022-04-27 00:44 ` David G. Johnston <david.g.johnston@gmail.com>
2022-04-27 01:20 ` Bryn Llewellyn <bryn@yugabyte.com>
2022-04-27 01:31 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-04-27 03:18 ` Bryn Llewellyn <bryn@yugabyte.com>
2022-04-27 09:32 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2022-04-27 13:48 ` Tom Lane <tgl@sss.pgh.pa.us>
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