Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mzOKd-0006xc-CY for pgsql-general@arkaria.postgresql.org; Mon, 20 Dec 2021 19:28:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mzOKc-0001tO-81 for pgsql-general@arkaria.postgresql.org; Mon, 20 Dec 2021 19:28:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mzOKb-0001tD-OZ for pgsql-general@lists.postgresql.org; Mon, 20 Dec 2021 19:28:21 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mzOKZ-0005Ys-9U for pgsql-general@lists.postgresql.org; Mon, 20 Dec 2021 19:28:20 +0000 Received: by mail-pj1-x1031.google.com with SMTP id v16so10326961pjn.1 for ; Mon, 20 Dec 2021 11:28:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=GW3kC759PyO6mOWEOgZFWme652+hHnDkHZ3U367PYF4=; b=GJFOMvYQwRciqovydwL/7SPiYNnGA+6SnaBjAzUWrf+64uN346GPKHYdBWAGu+jJrP eZO+IjaNEB30/lcn/bGCJnu12h8Jzph5mIBLAAzwQxwDieY8fX8diGFuk6itBv6YRfKm tBBh/vkBXunw8AfjvwPO5E54TAhHocQt8w6sM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=GW3kC759PyO6mOWEOgZFWme652+hHnDkHZ3U367PYF4=; b=PDmMavDxVAzoCr6XPp+EHYSyHBLH6TSx0XbHCp+7Xpz0VJpUZk1bSD1gWnPyccVJCf SECn/0Tx5wpBkonIBnTNV4BrPikxkd2eSyb9aZuL7wgyNxvIMTxCg0mihocLOf6SOykO bDytxhbQZ8MqkE0PVez16w0vog734Wqi4jE7ecqgt0dz2QxhxdfLU11LADttCVqPHr3i 3Ju1OJAn9J6jm26CNjnc7Chi8iHZClw9ouqNtCJK+2erkjWbzI7YhAeLO+EH8qOR1qbo /zIqO9kCzaIWyvhC7jbTaLBDUewWuVXWljFE1TRd9+VDOrCPbbjs4apGbF6hXXwr2e6B +nEg== X-Gm-Message-State: AOAM532Z87KSYfJK9wOrzT1eOHVE2zv92QvLUH1GBxetHVRdyvEoGrHg s2x4x+lXBAj4dMxqV88O13Ju5w== X-Google-Smtp-Source: ABdhPJxX2Jye9lYfxPYgwcNMB7LKP/XRpZI1XRI+zuKSeiZXpaR3lCwqABc7g0WBF+v2aneiXF7oWA== X-Received: by 2002:a17:902:d88b:b0:142:8acf:615b with SMTP id b11-20020a170902d88b00b001428acf615bmr18330837plz.62.1640028497998; Mon, 20 Dec 2021 11:28:17 -0800 (PST) Received: from smtpclient.apple ([2601:646:101:7fda:f9a2:dfb5:ab2d:472e]) by smtp.gmail.com with ESMTPSA id q19sm164742pjd.21.2021.12.20.11.28.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Dec 2021 11:28:17 -0800 (PST) From: Bryn Llewellyn Message-Id: <037CC942-B5B9-4D60-89CE-EBFD91D173DE@yugabyte.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_3D78B747-49EE-4B2A-986B-F2A3B302B918" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: Packages, inner subprograms, and parameterizable anonymous blocks for PL/pgSQL Date: Mon, 20 Dec 2021 11:28:16 -0800 In-Reply-To: <4C7E6E82-ACA1-4CCD-BFAC-89A11479C8C7@yugabyte.com> Cc: Peter Geoghegan , pgsql-general list , "David G. Johnston" , Adrian Klaver , Merlin Moncure , Pavel Stehule , Mladen Gogala , Laurenz Albe To: Bryn Llewellyn References: <48A5C07D-6A66-4B96-A48C-75C530CB9DCF@yugabyte.com> <9b782e8fbd6b324793c0f9f7188c197486dd2449.camel@cybertec.at> <4C7E6E82-ACA1-4CCD-BFAC-89A11479C8C7@yugabyte.com> X-Mailer: Apple Mail (2.3654.120.0.1.13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_3D78B747-49EE-4B2A-986B-F2A3B302B918 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 bryn@yugabyte.com wrote: >=20 >> pg@bowt.ie wrote: >>=20 >>> bryn@yugabyte.com wrote: >>>=20 >>> Modular design recommends exposing functionality through a purpose = oriented interface and hiding all implementation details from the = API=E2=80=99s user. A package achieves this with declarative syntax via = the spec/body separation. The body encapsulates as many (top-level) = subprograms as you want. Each of these is visible to all of its peers. = But none is visible outside of the package unless the spec declares that = it should be. This is a simple opt-in scheme. >>=20 >> I still don=E2=80=99t get it. It sounds like you=E2=80=99re mostly = talking about encapsulation, or Information hiding, for stored = procedures. I can certainly see how plpgsql doesn=E2=80=99t do those = things very well, but it still seems like there might be a lot of nuance = that isn=E2=80=99t getting across. The list of specific features that = seem to be missing are not unreasonable, individually, and yet it feels = like I cannot see some bigger picture that's apparent to you. >>=20 >> Maybe you should explain your position by way of a motivating = example, involving a real world use case. Something that makes the = issues concrete. Are these items compelling because of how they allow an = organization to deploy a program in a production environment, complete = with version control? Does it have something to do with decoupling the = mutable business data stored in tables from the programs contained/run = in the same database? >=20 > I can certainly make up an example. I=E2=80=99ll do this over the = weekend. However, I fear that it will be time wasted because at least = some of the addressees here who=E2=80=99ve expressed strong opposition = to the notion of PL/pgSQL packages must understand very well what = they=E2=80=99re objecting to. For example, pavel.stehule@gmail.com = with his =E2=80=9Cschema variables, LET = command=E2=80=9D work. >=20 > Anyway=E2=80=A6 I=E2=80=99ll give it my best shot. I=E2=80=99ll try to = address your specific questions in my follow-up reply. Hang on for a = couple of days, please. I made a start on this. But I want to think carefully about the example = use case(s). So I won=E2=80=99t promise a delivery date. Like I said, I = don=E2=80=99t expect to change anybody=E2=80=99s mind. But I do hope = that I might get some useful suggestions on how, using PG Version 14, I = can best meet the requirements that I=E2=80=99ll aim to explain. I=E2=80=99m still hoping that I might get some pointers to whitepapers = or blog posts that expand on those bullets that I quoted from the PG = doc: =C2=ABInstead of packages, use schemas to organize your functions = into groups.=C2=BB and =C2=ABSince there are no packages, there are no = package-level variables either. This is somewhat annoying. You can keep = per-session state in temporary tables instead.=C2=BB --Apple-Mail=_3D78B747-49EE-4B2A-986B-F2A3B302B918 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 bryn@yugabyte.com wrote:

pg@bowt.ie wrote:

bryn@yugabyte.com = wrote:

Modular = design recommends exposing functionality through a purpose oriented = interface and hiding all implementation details from the API=E2=80=99s = user. A package achieves this with declarative syntax via the = spec/body separation. The body encapsulates as many (top-level) = subprograms as you want. Each of these is visible to all of its peers. = But none is visible outside of the package unless the spec declares = that it should be. This is a simple opt-in scheme.

I still don=E2=80=99t get it. It sounds like you=E2=80=99re = mostly talking about encapsulation, or Information hiding, for = stored procedures. I can certainly see how plpgsql doesn=E2=80=99t = do those things very well, but it still seems like there might be a = lot of nuance that isn=E2=80=99t getting across. The list of = specific features that seem to be missing are not unreasonable, = individually, and yet it feels like I cannot see some bigger = picture that's apparent to you.

Maybe you = should explain your position by way of a motivating = example, involving a real world use case. Something that makes the = issues concrete. Are these items compelling because of how they = allow an organization to deploy a program in a production = environment, complete with version control? Does it have something = to do with decoupling the mutable business data stored in tables = from the programs contained/run in the same database?

I = can certainly make up an example. I=E2=80=99ll do this over the weekend. = However, I fear that it will be time wasted because at least some of the = addressees here who=E2=80=99ve expressed strong opposition to the notion = of PL/pgSQL packages must understand very well what they=E2=80=99re = objecting to. For example, pavel.stehule@gmail.com with his =E2=80=9Cschema = variables, LET command=E2=80=9D work.

Anyway=E2=80=A6 I=E2=80=99ll give it my = best shot. I=E2=80=99ll try to address your specific questions in my = follow-up reply. Hang on for a couple of days, = please.

I made a start on this. But I want to think carefully about = the example use case(s). So I won=E2=80=99t promise a delivery date. = Like I said, I don=E2=80=99t expect to change anybody=E2=80=99s mind. = But I do hope that I might get some useful suggestions on how, using PG = Version 14, I can best meet the requirements that I=E2=80=99ll aim to = explain.

I=E2=80= =99m still hoping that I might get some pointers to whitepapers or blog = posts that expand on those bullets that I quoted from the PG doc: = =C2=ABInstead of packages, use schemas to organize your functions into = groups.=C2=BB and =C2=ABSince there are no packages, there are no = package-level variables either. This is somewhat annoying. You can keep = per-session state in temporary tables = instead.=C2=BB

= --Apple-Mail=_3D78B747-49EE-4B2A-986B-F2A3B302B918--