Re: psql metaqueries with \gexec

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, PostgreSQL <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql metaqueries with \gexec
Date: 2016-02-22 23:13:13
Message-ID: 20160222231313.GA242371@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jim Nasby wrote:
> On 2/22/16 11:47 AM, Alvaro Herrera wrote:
> >Pavel Stehule wrote:
> >
> >>The design of the "format" function is not closed. Try to send prototype
> >>and patch. The possibility to do PostgreSQL customization was strong reason
> >>why we didn't implemented "sprintf" and we implemented "format".
> >
> >Probably not terribly useful here, but for the DDL-deparse patch I came
> >up with a syntax to format JSON objects, which used %-escapes; each
> >escaped element corresponds to a string literal, or to an object. So
> >you'd have %{table}D where the "table" element in the JSON object could
> >be a simple string which is expanded verbatim (plus quoting if
> >necessary), or it could be a JSON object with something like { schema =>
> >"public", name => "students" }, where each element is expanded and
> >quoted as necessary; if the "schema" is null or it doesn't exist, it
> >expands only the name, obviously omitting the dot.
>
> Where did the "D" in "%{table}D" come from?

The I in %{foo}I was for "identifier" (of course) and I *think* the D
was for "double identifiers" (that is, qualified). I expanded the idea
afterwards to allow for a third name for things like
catalog.schema.name, so I guess it's a misnomer already.

It's not released code yet. You can see an example here
https://www.postgresql.org/message-id/%3C20150224175152.GI5169%40alvh.no-ip.org%3E
just scroll down a few hundred lines to about 7/16ths of the page (yes,
really)

(One thing I had to come up with was processing of arrays, which you
also see in that example JSON -- it's the specifiers that have a colon
inside the {}. The part after the colon is used as separator between
the array elements, and each element is expanded separately.)

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Corey Huinker 2016-02-22 23:16:03 format() changes discussion (was: Re: psql metaqueries with \gexec)
Previous Message Thomas Munro 2016-02-22 23:11:21 Re: postgres_fdw vs. force_parallel_mode on ppc