Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rMz5r-008Epb-3D for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jan 2024 23:31:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rMz5q-008FVF-6F for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jan 2024 23:31:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rMz5p-008FV5-ST for pgsql-hackers@lists.postgresql.org; Mon, 08 Jan 2024 23:31:41 +0000 Received: from mail-oo1-xc29.google.com ([2607:f8b0:4864:20::c29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rMz5n-000Yjz-3D for pgsql-hackers@lists.postgresql.org; Mon, 08 Jan 2024 23:31:40 +0000 Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-5986f790b64so395330eaf.3 for ; Mon, 08 Jan 2024 15:31:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=neon.tech; s=google; t=1704756698; x=1705361498; darn=lists.postgresql.org; h=in-reply-to:references:to:subject:from:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=i4eRzgip2NxeS4rTPK5nS9iAJn8KcQssOUAZG1UA80A=; b=fSAktZPDxXrgg9aRBf+ougy2zse6bsrqPiIbF7AXXEcYhcwRm70hx1ujUQmniHvDTX tCoEaGN7eWuqyvhEV/KUTjX4TF7wpZB5353zNGddfDRjdJebWpHVhGB0ri9kJq3RaEY2 hqDhIdLiq2m7jZRkI3+NJLh+uTllNRZw8mTIc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704756698; x=1705361498; h=in-reply-to:references:to:subject:from:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=i4eRzgip2NxeS4rTPK5nS9iAJn8KcQssOUAZG1UA80A=; b=eRRKKEXlUgVHdql9RKGe1KUzYCV/QKg8UtoBOd+++/J9nx9mDCwWGw1hnDUFBUVYTy SWSF5y5dYOIfk0AJKN4n9GFvttXQYcJIqNAz/Q99w26iqKesBmC6NKIwZ+hn+sP4y71m XqrwxLxkZwoCD0A2mF9Fv2E2svDk03frgVT9qmnnbuEwH7KNvfLOGZYuVHAaF5/UDmbG ndvj3Fp5QGV+iJA6YpEZsOM0YZbZBF0hNLLLkHo9DWihob/fB/l4bc07nDey0bzosEHI gqst20ei3cgpEY/bdWAd9z//AoEILI1JCl4MVOrQosgBX6HtYzGxaiyXQsoDGt8P6w0i hv7w== X-Gm-Message-State: AOJu0YyRVWyin6vyZqN+aG1NLCNulTgiCBrWoBg5x4EvPzztBwEHaAQm 42avz9QZnDE3sJ+Q1ruew4rer3+dl88WEQ== X-Google-Smtp-Source: AGHT+IHNC9o3mWJ2/DgSR+KM2eoQYSsPYOn9FCgeXwgWRRujN79jmAaJIZOKvjlsDJuTrHakHEoVmQ== X-Received: by 2002:a4a:8c6b:0:b0:598:4de7:230d with SMTP id v40-20020a4a8c6b000000b005984de7230dmr1732187ooj.13.1704756698348; Mon, 08 Jan 2024 15:31:38 -0800 (PST) Received: from localhost ([2607:fb90:f21c:8167:3996:e070:71ee:42fb]) by smtp.gmail.com with ESMTPSA id a35-20020a4a98a6000000b00595a3e41e2csm130153ooj.37.2024.01.08.15.31.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Jan 2024 15:31:38 -0800 (PST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8; format=Flowed Date: Mon, 08 Jan 2024 17:31:37 -0600 Message-Id: From: "Tristan Partin" Subject: Re: Make psql ignore trailing semicolons in \sf, \ef, etc To: "Tom Lane" , X-Mailer: aerc 0.16.0-93-gbd29700e708d References: <2012251.1704746912@sss.pgh.pa.us> In-Reply-To: <2012251.1704746912@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon Jan 8, 2024 at 2:48 PM CST, Tom Lane wrote: > We had a complaint (see [1], but it's not the first IIRC) about how > psql doesn't behave very nicely if one ends \sf or allied commands > with a semicolon: > > regression=3D# \sf sin(float8); > ERROR: expected a right parenthesis > > This is a bit of a usability gotcha, since many other backslash > commands are forgiving about trailing semicolons. I looked at > the code and found that it's actually trying to ignore semicolons, > by passing semicolon =3D true to psql_scan_slash_option. But that > fails to work because it's also passing type =3D OT_WHOLE_LINE, > and the whole-line code path ignores the semicolon flag. Probably > that's just because nobody needed to use that combination back in > the day. There's another user of OT_WHOLE_LINE, exec_command_help, > which also wants this behavior and has written its own stripping > code to get it. That seems pretty silly, so here's a quick finger > exercise to move that logic into psql_scan_slash_option. > > Is this enough of a bug to deserve back-patching? I'm not sure. > > regards, tom lane > > [1] https://www.postgresql.org/message-id/CAEs%3D6D%3DnwX2wm0hjkaw6C_LnqR= %2BNFtnnzbSzeZq-xcfi_ooKSw%40mail.gmail.com > + /* > + * In whole-line mode, we interpret semicolon = =3D true as stripping > + * trailing whitespace as well as semi-colons; = this gives the > + * nearest equivalent to what semicolon =3D tru= e does in normal > + * mode. Note there's no concept of quoting in= this mode. > + */ > + if (semicolon) > + { > + while (mybuf.len > 0 && > + (mybuf.data[mybuf.len - 1] = =3D=3D ';' || > + (isascii((unsigned char= ) mybuf.data[mybuf.len - 1]) && > + isspace((unsigned char= ) mybuf.data[mybuf.len - 1])))) > + { > + mybuf.data[--mybuf.len] =3D '\0= '; > + } > + } Seems like if there was going to be any sort of casting, it would be to=20 an int, which is what the man page says for these two function, though=20 isascii(3) explicitly mentions "unsigned char." Small English nit-pick: I would drop the hyphen between semi and colons. As for backpatching, seems useful in the sense that people can write the=20 same script for all supported version of Postgres using the relaxed=20 syntax. --=20 Tristan Partin Neon (https://neon.tech)