Thread: tabs in psql

tabs in psql

From
Seb
Date:
Hi,

I'm fairly new to postgresql, and I'm having some problems understanding
the syntax of SQL statements in psql.  According to the documentation,
white space can be used freely.  However, the following fails:

CREATE TABLE test
 (
    id    Int8,
    phenotype Varchar(510),
    genotype  Varchar(510)
);
testdb(> ERROR:  syntax error at or near "Varchar"
LINE 4:     phenotype Varchar(510),
                      ^

where the field name and data type spec are separated by a tab
character.  However, this works if the tab is separated by a single
space.  Can someone please explain how this is controlled, and what the
proper syntax should be?  Thanks in advance.

Cheers,

--
Seb

Re: tabs in psql

From
"Joshua D. Drake"
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, 23 Mar 2008 19:35:46 -0500
Seb <spluque@gmail.com> wrote:

> CREATE TABLE test
>  (
>     id    Int8, 
>     phenotype Varchar(510), 
>     genotype  Varchar(510) 
> );

serial_test=# CREATE TABLE test
 (
    id Int8, 
    phenotype Varchar(510), 
    genotype  Varchar(510) 
);
CREATE TABLE


I can not duplicate your problem. However when I copy and paste
directly from your email it does indeed fail watch:

serial_test=# CREATE TABLE test
serial_test-#  (
serial_test(#     idInt8, 
serial_test(#     phenotype Varchar(510), 
serial_test(#     genotype  Varchar(510) 
serial_test(# );
ERROR:  syntax error at or near "Varchar"
LINE 4:     phenotype Varchar(510), 
                      ^

That is a direct copy and paste from your email. Notice that there is
no space between id and Int8. Once I manually put the space in, it
worked as expected.

Sincerely,

Joshua D. Drake


- -- 
The PostgreSQL Company since 1997: http://www.commandprompt.com/ 
PostgreSQL Community Conference: http://www.postgresqlconference.org/
United States PostgreSQL Association: http://www.postgresql.us/
Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFH5vpJATb/zqfZUUQRAk+zAJ0WerkdEjY2eDB24OBQMRn4iyHCngCfahBs
r8zG0uQChcr11XLkZ5dtY5A=
=k3m8
-----END PGP SIGNATURE-----

Re: tabs in psql

From
Seb
Date:
On Sun, 23 Mar 2008 17:48:09 -0700,
"Joshua D. Drake" <jd@commandprompt.com> wrote:

[...]

> I can not duplicate your problem. However when I copy and paste
> directly from your email it does indeed fail watch:

[...]

> That is a direct copy and paste from your email. Notice that there is
> no space between id and Int8. Once I manually put the space in, it
> worked as expected.

Thanks Joshua, that is the problem I wanted to illustrate; i.e.
whenever a tab separates the field name from the data type spec, the tab
character gets swallowed and psql cannot parse correctly.  So it seems
tabs are not interpreted as simple white space, and it should not be
used in this case, am I right?


--
Seb

Re: tabs in psql

From
"Joshua D. Drake"
Date:
On Sun, 23 Mar 2008 20:01:28 -0500
Seb <spluque@gmail.com> wrote:

> Thanks Joshua, that is the problem I wanted to illustrate; i.e.
> whenever a tab separates the field name from the data type spec, the
> tab character gets swallowed and psql cannot parse correctly.  So it
> seems tabs are not interpreted as simple white space, and it should
> not be used in this case, am I right?

Actually that would make sense as psql supports tab complete so if the
terminal interprets a tab, it isn't going to treat it as spaces. I
would suggest changing your editor to treat tabs as 4 spaces.

Sincerely,

Joshua D. Drake


--
The PostgreSQL Company since 1997: http://www.commandprompt.com/
PostgreSQL Community Conference: http://www.postgresqlconference.org/
Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate
PostgreSQL SPI Liaison | SPI Director |  PostgreSQL political pundit


Attachment

Re: tabs in psql

From
Seb
Date:
On Sun, 23 Mar 2008 18:15:55 -0700,
"Joshua D. Drake" <jd@commandprompt.com> wrote:

[...]

> Actually that would make sense as psql supports tab complete so if the
> terminal interprets a tab, it isn't going to treat it as spaces. I
> would suggest changing your editor to treat tabs as 4 spaces.

But the problem still occurs with 'psql -f INPUTFILE', where tab
complete is irrelevant, so I'm confused.


--
Seb

Re: tabs in psql

From
Tom Lane
Date:
Seb <spluque@gmail.com> writes:
> But the problem still occurs with 'psql -f INPUTFILE', where tab
> complete is irrelevant, so I'm confused.

You sure?  I can't make the example fail that way.  It does fail
when the example-with-tab is cut and pasted directly into a terminal
window, which is exactly as expected because that's exactly what
would happen if you interactively typed a TAB at that point.  psql
doesn't see anything to complete with so it just beeps at you, without
adding anything to the input.

If you need to enter stuff like this interactively in psql, use -n
to disable readline.

You really shouldn't need -n to prevent tab completion in a -f file
though.  If you can reproduce that then file a bug against whatever
version of readline you're using.

            regards, tom lane