Re: PgBench's \setrandom could be better - Mailing list pgsql-hackers

From Robert Haas
Subject Re: PgBench's \setrandom could be better
Date
Msg-id CA+Tgmoam5DS_xZtpoHp7B3iXxgDg2o_GWHCysQacFTVtkkgduQ@mail.gmail.com
Whole thread Raw
In response to PgBench's \setrandom could be better  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-hackers
On Sat, Nov 15, 2014 at 5:51 PM, David Rowley <dgrowleyml@gmail.com> wrote:
> With pgbench I can do:
>
> \setrandom qty 24 25
> then throw a :qty into the query and have pgbench replace that with either
> 24 or 25.
>
> The problem is that this does not work for anything apart from integer
> types.

I've got a pending patch here - which I don't think anyone has
reviewed - that adds an expression syntax to pgbench:

https://commitfest.postgresql.org/action/patch_view?id=1581

Once that patch goes in, I think we should generalize it so that the
\set syntax can use not only operators but also functions, like abs().
We could also generalize it to work on data types other than integers,
such as strings or (like you're suggesting here) dates, so that you
could have a random_date() function.

In general I'm pretty skeptical about continuing to expend pgbench by
adding more backslash commands and complicating the syntax of the ones
we've already got.  We can certainly do it that way, but it's kind of
a mess.  I'd rather have a more general framework to build on.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [BUGS] ltree::text not immutable?
Next
From: Fujii Masao
Date:
Subject: Re: pg_receivexlog --status-interval add fsync feedback