Обсуждение: Re: Documentation fix on pgbench \aset command

Поиск
Список
Период
Сортировка

Re: Documentation fix on pgbench \aset command

От
Yugo Nagata
Дата:
On Fri, 27 Jun 2025 01:05:47 +0900
Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

> 
> 
> On 2025/06/26 18:01, Yugo Nagata wrote:
> > Hi,
> > 
> > The current documentation of pgbench’s \aset command states:
> > 
> > “If a query returns no row, no assignment is made and the variable
> >   can be tested for existence to detect this.”
> > 
> > However, this is inaccurate, since variable existence check (like \if :{?var})
> > is not yet supported, although such a feature was proposed in [1] and discussed
> > again in [2], where \aset itself was introduced.
> 
> Right.
> 
> 
> > Therefore, I’ve attached a patch to remove this part from the documentation.
> 
> Or would it be worth documenting an alternative way to detect when no rows are
> returned? For example:
> 
>      If a query returns no rows, no variables are assigned. You can detect
>      this by setting an initial value to the variable before running the query
>      and checking whether it changes.

That's what I thought as well, but I didn’t do it because we can’t distinguish it
from the case where the query returns the same value as the initial one.

To detect it correctly, we would need to reconsider the variable existence check,
or introduce a new meta-command or a special variable that indicates the number of
rows returned by the previous query, and so on.

Regards,
Yugo Nagata


-- 
Yugo Nagata <nagata@sraoss.co.jp>



Re: Documentation fix on pgbench \aset command

От
Fujii Masao
Дата:

On 2025/06/27 1:31, Yugo Nagata wrote:
> On Fri, 27 Jun 2025 01:05:47 +0900
> Fujii Masao <masao.fujii@oss.nttdata.com> wrote:
> 
>>
>>
>> On 2025/06/26 18:01, Yugo Nagata wrote:
>>> Hi,
>>>
>>> The current documentation of pgbench’s \aset command states:
>>>
>>> “If a query returns no row, no assignment is made and the variable
>>>    can be tested for existence to detect this.”
>>>
>>> However, this is inaccurate, since variable existence check (like \if :{?var})
>>> is not yet supported, although such a feature was proposed in [1] and discussed
>>> again in [2], where \aset itself was introduced.
>>
>> Right.
>>
>>
>>> Therefore, I’ve attached a patch to remove this part from the documentation.
>>
>> Or would it be worth documenting an alternative way to detect when no rows are
>> returned? For example:
>>
>>       If a query returns no rows, no variables are assigned. You can detect
>>       this by setting an initial value to the variable before running the query
>>       and checking whether it changes.
> 
> That's what I thought as well, but I didn’t do it because we can’t distinguish it
> from the case where the query returns the same value as the initial one.

Could we use a value that the query is guaranteed not to return as the initial value?
For example, in SELECT id AS myid FROM test \aset, if the id column is of type integer,
we could initialize myid to FALSE.


> To detect it correctly, we would need to reconsider the variable existence check,
> or introduce a new meta-command or a special variable that indicates the number of
> rows returned by the previous query, and so on.

+1

Regards,

-- 
Fujii Masao
NTT DATA Japan Corporation




Re: Documentation fix on pgbench \aset command

От
Yugo Nagata
Дата:
On Fri, 27 Jun 2025 01:45:16 +0900
Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

> 
> 
> On 2025/06/27 1:31, Yugo Nagata wrote:
> > On Fri, 27 Jun 2025 01:05:47 +0900
> > Fujii Masao <masao.fujii@oss.nttdata.com> wrote:
> > 
> >>
> >>
> >> On 2025/06/26 18:01, Yugo Nagata wrote:
> >>> Hi,
> >>>
> >>> The current documentation of pgbench’s \aset command states:
> >>>
> >>> “If a query returns no row, no assignment is made and the variable
> >>>    can be tested for existence to detect this.”
> >>>
> >>> However, this is inaccurate, since variable existence check (like \if :{?var})
> >>> is not yet supported, although such a feature was proposed in [1] and discussed
> >>> again in [2], where \aset itself was introduced.
> >>
> >> Right.
> >>
> >>
> >>> Therefore, I’ve attached a patch to remove this part from the documentation.
> >>
> >> Or would it be worth documenting an alternative way to detect when no rows are
> >> returned? For example:
> >>
> >>       If a query returns no rows, no variables are assigned. You can detect
> >>       this by setting an initial value to the variable before running the query
> >>       and checking whether it changes.
> > 
> > That's what I thought as well, but I didn’t do it because we can’t distinguish it
> > from the case where the query returns the same value as the initial one.
> 
> Could we use a value that the query is guaranteed not to return as the initial value?
> For example, in SELECT id AS myid FROM test \aset, if the id column is of type integer,
> we could initialize myid to FALSE.

This will work if we assume that the query never returns the initial value.
I've attached a updated patch that fix the documentation as below:

 If a query returns no rows, no assignment is made. You can detect
 this by initializing the variable beforehand with a value that the query is
 assumed never to return, and then checking whether it changes.
 
Regards,
Yugo Nagata


-- 
Yugo Nagata <nagata@sraoss.co.jp>

Вложения

Re: Documentation fix on pgbench \aset command

От
Fujii Masao
Дата:
On Fri, Jun 27, 2025 at 10:37 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:
> This will work if we assume that the query never returns the initial value.
> I've attached a updated patch that fix the documentation as below:
>
>  If a query returns no rows, no assignment is made. You can detect
>  this by initializing the variable beforehand with a value that the query is
>  assumed never to return, and then checking whether it changes.

Thanks for updating the patch!

While reviewing the descriptions for \gset and \aset, I noticed they're listed
as a single term. I think it would be clearer to list them separately.
Also, there's no explanation of what happens if the query with \gset returns
zero or multiple rows, so I'd like to add that too. Thought?

I've attached an updated version of the patch with these changes applied.

Regards,

--
Fujii Masao

Вложения

Re: Documentation fix on pgbench \aset command

От
Yugo Nagata
Дата:
On Mon, 22 Sep 2025 16:19:14 +0900
Fujii Masao <masao.fujii@gmail.com> wrote:

> On Fri, Jun 27, 2025 at 10:37 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:
> > This will work if we assume that the query never returns the initial value.
> > I've attached a updated patch that fix the documentation as below:
> >
> >  If a query returns no rows, no assignment is made. You can detect
> >  this by initializing the variable beforehand with a value that the query is
> >  assumed never to return, and then checking whether it changes.
> 
> Thanks for updating the patch!
> 
> While reviewing the descriptions for \gset and \aset, I noticed they're listed
> as a single term. I think it would be clearer to list them separately.
> Also, there's no explanation of what happens if the query with \gset returns
> zero or multiple rows, so I'd like to add that too. Thought?
> 
> I've attached an updated version of the patch with these changes applied.

Thank you for your suggestion and updating the patch.
I'm fine with your version since it is clearer.

Regards,
Yugo Nagata

-- 
Yugo Nagata <nagata@sraoss.co.jp>



Re: Documentation fix on pgbench \aset command

От
Fujii Masao
Дата:
On Thu, Sep 25, 2025 at 11:12 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:
> Thank you for your suggestion and updating the patch.
> I'm fine with your version since it is clearer.

I've pushed the patch. Thanks!

Regards,

--
Fujii Masao