Re: patch: psql variables tabcomplete

From: Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: patch: psql variables tabcomplete
Date: 2010-10-04 08:17:06
Message-ID: AANLkTinh3MvwbQao_vg83B8NF5rcLmAWWF-pw-vUTF92@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Aug 16, 2010 at 8:32 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> fixed spelling
>
> 2010/8/16 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
>> I found so there are not support for tabcomple of psql variables.

Contents & Purpose
==================
This small patch adds support for tab-completion of \set meta command in psql.
Variables that can be set with \set include not only user-defined ones but also
many pre-defined ones. So, the patch is useful to remember variable names.

Initial Run
===========
The patch can be applied to git master with one hunk, but it's not a problem.
Hunk #1 succeeded at 2582 (offset 65 lines).

It can be compiled with no warnings, but it might be better to add an explicit
cast for the void * returned from realloc() (if we continue to use it;
see below).

Performance
===========
Since we don't have so many variables at once in normal use, the tab completion
won't be a performance critical part.

Bugs, suggestions, etc.
=======================
BUG: If we have just 100 variables, there is a buffer overrun for the last
NULL sentinel.

realloc() is used in the patch, but it is rarely used in the existing codes.
It is used in converting a single-linked list into an array, but we could
remove it if we use two loops (for length and for copying). Or, we will
still use realloc, a wrapper for pg_realloc() might be better than using
realloc() directly to avoid "out of memory" checks for each callee.

We don't have commands for display a list of such variables and \echo is
not tab-completed even with the patch. "Only supported by \set" might be
a bit unbalanced.

--
Itagaki Takahiro

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thom Brown 2010-10-04 08:24:49 Re: Additional index entries and table sorting
Previous Message Heikki Linnakangas 2010-10-04 07:56:36 Re: is sync rep stalled?