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 1nLjV8-0005E3-CU for pgsql-general@arkaria.postgresql.org; Sun, 20 Feb 2022 10:31:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nLjV7-00029x-7A for pgsql-general@arkaria.postgresql.org; Sun, 20 Feb 2022 10:31:33 +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 1nLjV6-00027Q-QP for pgsql-general@lists.postgresql.org; Sun, 20 Feb 2022 10:31:32 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nLjV0-0008Fc-JR for pgsql-general@lists.postgresql.org; Sun, 20 Feb 2022 10:31:31 +0000 Received: by mail-ej1-x62a.google.com with SMTP id qk11so25765437ejb.2 for ; Sun, 20 Feb 2022 02:31:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=LXVS5hqb9l2xJw681yiBhrkQr4K8ds2u6DOl9VVmI2o=; b=FyvBqWceP6mnFclIBWFwy5MKSOh6qg3vEUnWYqch/4te8szWhX/X3NJ/B8Ksnjc9GE /Mc47Kdgt8+V+3t5uBlrCJpaNOWq5G8JMdwVOQjEZlYTjZLdzDyMdHAH6VHmGpFMGUE4 Jzm5h3eq0tf6NTzZLEAPr0n77CUmTzn7o/EAg+vl5pgIrXB6g85N2s7Ndg03OvMaPbyg 2tiWG7AwrP18/SdKbtZae+RjJAcLEU9V7mZMjwXijDfO3F4rZEr9GuHZ8bK+EqcTd7/0 JP/FbTadD9NACI+Mhuycnx3VgdbOPChGEc2+8GopJUAs51Cyn314kotYEfeYSH8WKyTc 4S8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=LXVS5hqb9l2xJw681yiBhrkQr4K8ds2u6DOl9VVmI2o=; b=tka/Zl61ldMh9Y1/YzEEPlHqJ4ZfYtNNSx7pEpMisO1gbe6Y+CEacgZZGMlaRFhfb5 rBepLKIQew2NR5ZaxJ3cKYjddygExEr+J+7/J/7EPVadQ356Gerqfn2g7kLyhgrfLeRG HNuHsBIApF0CsaO5bSiIxGGjlKQd/mIZ2MpzFg2NSfRMjB35u1yXkQRFRF+nNwNdAydA ZWqMkhy+tEhM1eTKfwvi3KAC51b5r0mdcOtQ+yfqY/7+PpBq8t0WbtFadn6NihtUCW0s nwKdg7e552vwznH8O83RUDTMH7drfEA18hV4PjtmEvx5175QmmzOB9KcX7uLtZEY5bWP NjpQ== X-Gm-Message-State: AOAM533gk7t4iApakdSsfL/BeF4h8DyPqjI7e5WadYD5ND5w2rcHUe0m eNrElXAt0DkQLiGrRcaedfw= X-Google-Smtp-Source: ABdhPJyNjBVu6Vkk62oNX1SaxTAm9RW56Tb5zobLthSFHdOeDMz2Gk23xNm2To2g4uPEXLc/KhwLGA== X-Received: by 2002:a17:906:8299:b0:6cf:3847:284b with SMTP id h25-20020a170906829900b006cf3847284bmr12141837ejx.682.1645353084686; Sun, 20 Feb 2022 02:31:24 -0800 (PST) Received: from smtpclient.apple (ppp-94-66-221-132.home.otenet.gr. [94.66.221.132]) by smtp.gmail.com with ESMTPSA id ej19sm4865686edb.108.2022.02.20.02.31.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Feb 2022 02:31:23 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.60.0.1.1\)) Subject: Re: Additional accessors via the Extension API ? From: Markur Sens In-Reply-To: <20220220101257.dchizxpkang7vvq4@jrouhaud> Date: Sun, 20 Feb 2022 12:31:22 +0200 Cc: pgsql-general Content-Transfer-Encoding: quoted-printable Message-Id: <2C9AEE7B-89A0-49F6-AB28-F81AEC9B6078@gmail.com> References: <6D4DE1F2-70C9-4BC4-92FD-0699BE0F8952@gmail.com> <20220220101257.dchizxpkang7vvq4@jrouhaud> To: Julien Rouhaud X-Mailer: Apple Mail (2.3693.60.0.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 20 Feb 2022, at 12:12 PM, Julien Rouhaud = wrote: >=20 > Hi, >=20 > On Sun, Feb 20, 2022 at 08:07:20AM +0200, Markur Sens wrote: >> Suppose I have defined an additional type in a PG extension. >>=20 >> Is it possible to add custom accessors to that type -much like jsonb = does- >> but use an API/hook without touching the core PG grammar & parser? >=20 > Unfortunately no. >=20 >> Hypothetical Examples: >>=20 >> Assuming I have a TextFile type I=E2=80=99d like to implement syntax = like: >>=20 >> (=E2=80=98/home/me/a.txt=E2=80=99::TextFile).firstline >> (=E2=80=98/home/me/a.txt=E2=80=99::TextFile).lastline >> (=E2=80=98/home/me/a.txt=E2=80=99::TextFile).countlines() >> (=E2=80=98/home/me/a.txt=E2=80=99::TextFile).size() >> (=E2=80=98/home/me/a.txt=E2=80=99::TextFile).datemodified() >=20 > Maybe you could rely on some old grammar hack to have something a bit = similar, > as (expr).funcname is an alias for funcname(expr). For instance: Is this documented & expected behavior or it=E2=80=99s just happens to = work? >=20 > # create function f1(int) returns text as $$ > begin > return 'val: ' || $1::text; > end; > $$ language plpgsql; >=20 > # create table t as select 1 as id; >=20 > # select (5).f1, (id).f1 from t; > f1 | f1 > --------+-------- > val: 5 | val: 1 > (1 row) >=20 > I don't know if that would be enough for you needs. Otherwise, the = only option > would be tocreate an operator instead, like mytype -> 'myaccessor' or = something > like that. Yes, that=E2=80=99s what I=E2=80=99m doing at the moment: Syntax like type -> =E2=80=98accessor=E2=80=99 is pretty straight = forward to implement as an operator as the rightarg is text. Things get more complicating as I=E2=80=99m adding support for mytype -> function(arg=3D1)=20 for that case I have to create an intermediate type of function(arg) so = that I can then define the left and right args for the -> operator. But it=E2=80=99s a lot of boilerplate code.