RE: Bug of psql meta-command \sf & \sv

Поиск
Список
Период
Сортировка
От Jet Zhang
Тема RE: Bug of psql meta-command \sf & \sv
Дата
Msg-id TY3P286MB2594818653BF91EEA0F0E43CD5C2A@TY3P286MB2594.JPNP286.PROD.OUTLOOK.COM
обсуждение исходный текст
Ответ на Re: Bug of psql meta-command \sf & \sv  (Japin Li <japinli@hotmail.com>)
Список pgsql-bugs

Yes, you’re right. Maybe we can spend some effort to strength the function psgl_scan_slash_option.

 

 

 

章晨曦  Jet C.X. ZHANG

18657181679

易景科技 http://www.halodbtech.com

浙江省杭州市滨江区长河街道建业路511号华创大厦5505

 

 

From: Japin Li
Sent: 2023
927 18:33
To: Jet Zhang
Cc: Daniel Gustafsson; pgsql-bugs@lists.postgresql.org
Subject: Re: Bug of psql meta-command \sf & \sv

 


On Wed, 27 Sep 2023 at 17:25, Jet Zhang <jet.cx.zhang@hotmail.com> wrote:
> I don’t think not a bug. As you said Semi-colon is not a meta-command terminator, but why the other meta-commands
> Exp. \dt able to work with Semi-colon?
>
> postgres=# \dt pg_class
>            List of relations
>    Schema   |   Name   | Type  | Owner
> ------------+----------+-------+-------
> pg_catalog | pg_class | table | jet
> (1 row)
>
> postgres=# \dt pg_class;
>            List of relations
>    Schema   |   Name   | Type  | Owner
> ------------+----------+-------+-------
> pg_catalog | pg_class | table | jet
> (1 row)
>
>

The \sf use the whole line as its input, it can accept more complex input,
for example:

postgres=# \sf test (int)
CREATE OR REPLACE PROCEDURE public.test(IN id integer)
 LANGUAGE plpgsql
AS $procedure$ BEGIN NULL; END; $procedure$
postgres=# \sf test (int, text)
CREATE OR REPLACE PROCEDURE public.test(IN id integer, IN info text)
 LANGUAGE plpgsql
AS $procedure$ BEGIN NULL; END; $procedure$

Same as \ef.

OTOH, \ev and \sv use same function as \ef and \sf, See exec_command_ef_ev()
and exec_command_sf_sv() in src/bin/psql/common.c file.

static backslashResult
exec_command_sf_sv(PsqlScanState scan_state, bool active_branch,
                   const char *cmd, bool is_func)
{
    backslashResult status = PSQL_CMD_SKIP_LINE;

    if (active_branch)
    {
        bool        show_linenumbers = (strchr(cmd, '+') != NULL);
        PQExpBuffer buf;
        char       *obj_desc;
        Oid         obj_oid = InvalidOid;
        EditableObjectType eot = is_func ? EditableFunction : EditableView;

        buf = createPQExpBuffer();
        obj_desc = psql_scan_slash_option(scan_state,
                                          OT_WHOLE_LINE, NULL, true);
                                          ^    -- use the whole line

Maybe we can split \sf and \sv, however, I'm not sure it worth.

--
Regrads,
Japin Li
ChengDu WenWu Information Technology Co., Ltd.

 

Вложения

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Japin Li
Дата:
Сообщение: Re: Bug of psql meta-command \sf & \sv
Следующее
От: Daniel Gustafsson
Дата:
Сообщение: Re: Memory leak on subquery as scalar operand