Two successive tabs in test case are causing syntax error in psql

Started by Jingtang Zhangover 3 years ago4 messages
#1Jingtang Zhang
mrdrivingduck@gmail.com
1 attachment(s)

Hi, community.

Recently, when I was developing some function about INSERT ... ON CONFLICT,
I used test cases in `src/test/regress/sql/insert_conflict.sql` to evaluate
my function. When I copy the CREATE TABLE from this case alone, and paste
it to psql, I got a syntax error. As I go through the case carefully, I
found the CREATE TABLE uses two tabs to separate column name and column
type, and this two tabs are regarded as an auto completion instruction by
psql, causing no separation between column name and column type anymore.

It may not be a problem since this case has passed the regression, but
would it be better to use space here to avoid this confusing situation?
Since other part of this case are all using spaces.

Never mind my opinion as a beginner, thanks.

Jingtang Zhang

Attachments:

0001-Fix-two-tabs-are-regarded-as-auto-completion-in-test.patchapplication/octet-stream; name=0001-Fix-two-tabs-are-regarded-as-auto-completion-in-test.patchDownload
From ca3a76d92277b8e5369b8f99c1ff0051f9d5ee70 Mon Sep 17 00:00:00 2001
From: Jingtang Zhang <mrdrivingduck@gmail.com>
Date: Fri, 8 Jul 2022 22:58:10 +0800
Subject: [PATCH] Fix two tabs are regarded as auto completion in test case

In this test case, when I paste the CREATE TABLE into psql,
two tabs between `name` and `text`, which are originally used for
seperation, are regarded as auto completion instruction by psql,
causing syntax error because there is no more seperation between
column name and type. Would it be better to use space here, although
the tabs are not breaking the regression?
---
 src/test/regress/expected/insert_conflict.out | 10 +++++-----
 src/test/regress/sql/insert_conflict.sql      | 10 +++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/test/regress/expected/insert_conflict.out b/src/test/regress/expected/insert_conflict.out
index 66d8633e3e..fe32c4947d 100644
--- a/src/test/regress/expected/insert_conflict.out
+++ b/src/test/regress/expected/insert_conflict.out
@@ -497,12 +497,12 @@ drop table insertconflict;
 -- *                                                                *
 -- ******************************************************************
 create table cities (
-	name		text,
-	population	float8,
-	altitude	int		-- (in ft)
+  name    text,
+  population  float8,
+  altitude  int   -- (in ft)
 );
 create table capitals (
-	state		char(2)
+  state   char(2)
 ) inherits (cities);
 -- Create unique indexes.  Due to a general limitation of inheritance,
 -- uniqueness is only enforced per-relation.  Unique index inference
@@ -847,7 +847,7 @@ declare
     r record;
 begin
  for r in select * from inserted loop
-	raise notice 'a = %, b = %, c = %', r.a, r.b, r.c;
+  raise notice 'a = %, b = %, c = %', r.a, r.b, r.c;
  end loop;
  return new;
 end;
diff --git a/src/test/regress/sql/insert_conflict.sql b/src/test/regress/sql/insert_conflict.sql
index 23d5778b82..bfd3554927 100644
--- a/src/test/regress/sql/insert_conflict.sql
+++ b/src/test/regress/sql/insert_conflict.sql
@@ -307,13 +307,13 @@ drop table insertconflict;
 -- *                                                                *
 -- ******************************************************************
 create table cities (
-	name		text,
-	population	float8,
-	altitude	int		-- (in ft)
+  name    text,
+  population  float8,
+  altitude  int   -- (in ft)
 );
 
 create table capitals (
-	state		char(2)
+  state   char(2)
 ) inherits (cities);
 
 -- Create unique indexes.  Due to a general limitation of inheritance,
@@ -559,7 +559,7 @@ declare
     r record;
 begin
  for r in select * from inserted loop
-	raise notice 'a = %, b = %, c = %', r.a, r.b, r.c;
+  raise notice 'a = %, b = %, c = %', r.a, r.b, r.c;
  end loop;
  return new;
 end;
-- 
2.34.1

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jingtang Zhang (#1)
Re: Two successive tabs in test case are causing syntax error in psql

Jingtang Zhang <mrdrivingduck@gmail.com> writes:

Recently, when I was developing some function about INSERT ... ON CONFLICT,
I used test cases in `src/test/regress/sql/insert_conflict.sql` to evaluate
my function. When I copy the CREATE TABLE from this case alone, and paste
it to psql, I got a syntax error. As I go through the case carefully, I
found the CREATE TABLE uses two tabs to separate column name and column
type, and this two tabs are regarded as an auto completion instruction by
psql, causing no separation between column name and column type anymore.

It may not be a problem since this case has passed the regression, but
would it be better to use space here to avoid this confusing situation?

There are tabs all through the regression test files, and we're certainly
not going to remove them all. (If we did, we'd lose test coverage of
whether the parser accepts tabs as whitespace.) So I can't get excited
about removing one or two.

The usual recommendation for pasting text into psql when it contains
tabs is to start psql with the -n switch to disable tab completion.

regards, tom lane

#3Jingtang Zhang
mrdrivingduck@gmail.com
In reply to: Tom Lane (#2)
Re: Two successive tabs in test case are causing syntax error in psql

I see, thank you.

Tom Lane <tgl@sss.pgh.pa.us> 于2022年7月9日周六 03:35写道:

Show quoted text

Jingtang Zhang <mrdrivingduck@gmail.com> writes:

Recently, when I was developing some function about INSERT ... ON

CONFLICT,

I used test cases in `src/test/regress/sql/insert_conflict.sql` to

evaluate

my function. When I copy the CREATE TABLE from this case alone, and paste
it to psql, I got a syntax error. As I go through the case carefully, I
found the CREATE TABLE uses two tabs to separate column name and column
type, and this two tabs are regarded as an auto completion instruction by
psql, causing no separation between column name and column type anymore.

It may not be a problem since this case has passed the regression, but
would it be better to use space here to avoid this confusing situation?

There are tabs all through the regression test files, and we're certainly
not going to remove them all. (If we did, we'd lose test coverage of
whether the parser accepts tabs as whitespace.) So I can't get excited
about removing one or two.

The usual recommendation for pasting text into psql when it contains
tabs is to start psql with the -n switch to disable tab completion.

regards, tom lane

#4Alvaro Herrera
alvherre@alvh.no-ip.org
In reply to: Tom Lane (#2)
Re: Two successive tabs in test case are causing syntax error in psql

On 2022-Jul-08, Tom Lane wrote:

The usual recommendation for pasting text into psql when it contains
tabs is to start psql with the -n switch to disable tab completion.

"Bracketed paste" also solves this problem. To enable this feature,
just edit your $HOME/.inputrc file to have the line
set enable-bracketed-paste on
(then restart psql) which will cause the text passed to be used
literally, so the tabs won't invoke tab-completion. There are other
side-effects: if you paste a multi-command string, the whole string is
added as a single entry in the history rather than being separate
entries. I find this extremely useful; there are also claims of this
being more secure.

--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/