Re: psql tabcomplete - minor bugfix - tabcomplete for SET ROLE TO xxx - Mailing list pgsql-hackers

From Andres Freund
Subject Re: psql tabcomplete - minor bugfix - tabcomplete for SET ROLE TO xxx
Date
Msg-id 20150902132347.GD25109@alap3.anarazel.de
Whole thread Raw
In response to Re: psql tabcomplete - minor bugfix - tabcomplete for SET ROLE TO xxx  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: psql tabcomplete - minor bugfix - tabcomplete for SET ROLE TO xxx  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers
Hi,

On 2015-07-08 14:50:37 +0200, Pavel Stehule wrote:
> -            static const char *const my_list[] =
> -            {"DEFAULT", NULL};
> +            /* fallback for GUC settings */
>  
> -            COMPLETE_WITH_LIST(my_list);
> +            char *vartype = get_vartype(prev2_wd);
> +
> +            if (strcmp(vartype, "enum") == 0)
> +            {
> +                char querybuf[1024];
> +
> +                snprintf(querybuf, 1024, Query_for_enum, prev2_wd);
> +                COMPLETE_WITH_QUERY(querybuf);
> +            }

Won't that mean that enum variables don't complete to default anymore?

> +static char *
> +get_vartype(const char *varname)
> +{
> +    PQExpBufferData query_buffer;
> +    char    *e_varname;
> +    PGresult *result;
> +    int    string_length;
> +    static char resbuf[10];
> +
> +    initPQExpBuffer(&query_buffer);
> +
> +    string_length = strlen(varname);
> +    e_varname = pg_malloc(string_length * 2 + 1);
> +    PQescapeString(e_varname, varname, string_length);

Independent of this patch, we really shouldn't do this in several places
:(

> +    appendPQExpBuffer(&query_buffer,
> +        "SELECT vartype FROM pg_settings WHERE pg_catalog.lower(name) = pg_catalog.lower('%s')",
> +             e_varname);

Missing pg_catalog for pg_settings.

Greetings,

Andres Freund



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: [POC] FETCH limited by bytes.
Next
From: Andres Freund
Date:
Subject: Re: Allow a per-tablespace effective_io_concurrency setting