Re: Why can't I have a "language sql" anonymous block?

From: Bryn Llewellyn <bryn(at)yugabyte(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Tom Lane PostgreSQL <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Why can't I have a "language sql" anonymous block?
Date: 2021-12-15 00:08:36
Message-ID: 25643215-899C-4FF8-A35F-85A61A8AD0A5@yugabyte.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> david(dot)g(dot)johnston(at)gmail(dot)com wrote:
>
>> On Monday, December 13, 2021, Bryn Llewellyn <bryn(at)yugabyte(dot)com <mailto:bryn(at)yugabyte(dot)com>> wrote:
>>
>> There must be a reason to prefer a “language sql” procedure over a “language plpgsql” procedure—otherwise the former wouldn’t be supported.
>
> I would say that is true for functions. I wouldn’t assume that for procedures—it’s probable that because sql already worked for functions we got that feature for free when implementing procedures.

Interesting. That’s exactly the kind of historical insight I was after. Thanks.

It’s very tempting to think that “language sql” is meaningful only as a performance feature and in that connection only for a stored function because only a function can be inlined in a surrounding regular SQL statement. (You can invoke a procedure only as a singleton in the dedicated “call” statement.) In other words there can be no inlining benefit for a stored procedure.

It’s certainly no problem for the coder to bracket what would have been the body of a “language sql” DO block with a single “begin… end;”.

I should save any of you the effort of telling me this: a DO block is an anonymous, ephemeral procedure. It’s certainly not an anonymous function.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martín Fernández 2021-12-15 03:15:27 Reindex "locked" standby database
Previous Message Peter Geoghegan 2021-12-15 00:02:23 Re: When Update balloons memory