Re: pgbench - add \aset to store results of a combined query
Fabien COELHO <coelho@cri.ensmp.fr>
From: Fabien COELHO <coelho@cri.ensmp.fr>
To: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2019-05-23T14:10:55Z
Lists: pgsql-hackers
Attachments
- pgbench-aset-2.patch (text/x-diff) patch
V2 is a rebase. > A long time ago I submitted a pgbench \into command to store results of > queries into variables independently of the query being processed, which got > turn into \gset (;) and \cset (\;), which got committed, then \cset was > removed because it was not "up to standard", as it could not work with empty > query (the underlying issue is that pg silently skips empty queries, so that > "\; SELECT 1 \; \; SELECT 3," returns 2 results instead of 4, a misplaced > optimisation from my point of view). > > Now there is a pgbench \gset which allows to extract the results of variables > of the last query, but as it does both setting and ending a query at the same > time, there is no way to set variables out of a combined (\;) query but the > last, which is the kind of non orthogonal behavior that I dislike much. > > This annoys me because testing the performance of combined queries cannot be > tested if the script needs to extract variables. > > To make the feature somehow accessible to combined queries, the attached > patch adds the "\aset" (all set) command to store all results of queries > which return just one row into variables, i.e.: > > SELECT 1 AS one \; > SELECT 2 AS two UNION SELECT 2 \; > SELECT 3 AS three \aset > > will set both "one" and "three", while "two" is not set because there were > two rows. It is a kind of more permissive \gset. > > Because it does it for all queries, there is no need for synchronizing with > the underlying queries, which made the code for \cset both awkward and with > limitations. Hopefully this version might be "up to standard". > I'll see. I'm in no hurry:-) > > -- Fabien.
Commits
-
Add support for \aset in pgbench
- 9d8ef98800bd 13.0 landed