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

From: Jet Zhang <jet(dot)cx(dot)zhang(at)hotmail(dot)com>
To: Japin Li <japinli(at)hotmail(dot)com>
Cc: Daniel Gustafsson <daniel(at)yesql(dot)se>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: RE: Bug of psql meta-command \sf & \sv
Date: 2023-09-27 11:03:48
Message-ID: TY3P286MB2594818653BF91EEA0F0E43CD5C2A@TY3P286MB2594.JPNP286.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

[cid:image001(dot)png(at)01D80E0F(dot)FAC36F80]

章晨曦 Jet C.X. ZHANG
18657181679
易景科技 http://www.halodbtech.com
浙江省杭州市滨江区长河街道建业路511号华创大厦5层505

From: Japin Li<mailto:japinli(at)hotmail(dot)com>
Sent: 2023年9月27日 18:33
To: Jet Zhang<mailto:jet(dot)cx(dot)zhang(at)hotmail(dot)com>
Cc: Daniel Gustafsson<mailto:daniel(at)yesql(dot)se>; pgsql-bugs(at)lists(dot)postgresql(dot)org<mailto:pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: Bug of psql meta-command \sf & \sv

On Wed, 27 Sep 2023 at 17:25, Jet Zhang <jet(dot)cx(dot)zhang(at)hotmail(dot)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.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Daniel Gustafsson 2023-09-27 12:07:16 Re: Memory leak on subquery as scalar operand
Previous Message Japin Li 2023-09-27 10:33:42 Re: Bug of psql meta-command \sf & \sv