Thread: parse error at or near "(" -- Huh???

parse error at or near "(" -- Huh???

From
Alex Beamish
Date:
Hi,

I'm getting a frustrating error
 ERROR:  parser: parse error at or near "(" at character 201

in a CREATE TABLE statement from an SQL script that I'm running from
within a Perl script. When I run the same script from the command
line, either as a regular user or as root, it works fine.

The SQL is
---------------------------------------------------------
CREATE SEQUENCE "users_id"START 1 INCREMENT 1 MAXVALUE 2147483647 MINVALUE 1 CACHE 1;

CREATE TABLE "users" ("u_id" integer DEFAULT nextval('users_id'::text) NOT NULL,"u_name" text NOT NULL,"u_password"
textNOT NULL,"u_console_flag" integer DEFAULT 0,Constraint "users_pkey" Primary Key ("u_id")
 
);
---------------------------------------------------------

The 'console_flag' field was recently added and is close-ish to the
point that I think the parser is failing. And speaking of that, how I
am to interpret 'character 201' -- should I collapse the SQL into it's
minimal state (least number spaces) and go from that?

Thanks.

Alex

ps Tried to join the list using 
http://webmail.postgresql.org/mj/mj_wwwusr?domain=postgresql.org&func=lists-long-full&extra=pgsql-sql
but got a server timeout. :(


Re: parse error at or near "(" -- Huh???

From
Michael Fuhr
Date:
On Thu, Dec 09, 2004 at 03:19:56PM -0500, Alex Beamish wrote:

> I'm getting a frustrating error
> 
>   ERROR:  parser: parse error at or near "(" at character 201
> 
> in a CREATE TABLE statement from an SQL script that I'm running from
> within a Perl script. When I run the same script from the command
> line, either as a regular user or as root, it works fine.

Your SQL statements ran fine for me, so please show us a small but
complete Perl script that duplicates the problem.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


Re: parse error at or near "(" -- Huh???

From
Tom Lane
Date:
Alex Beamish <talexb@gmail.com> writes:
> I'm getting a frustrating error
>   ERROR:  parser: parse error at or near "(" at character 201
> in a CREATE TABLE statement from an SQL script that I'm running from
> within a Perl script. When I run the same script from the command
> line, either as a regular user or as root, it works fine.

One would have to suppose that the Perl environment is somehow munging
the SQL commands you think you are sending.  Try enabling statement
logging on the server side --- when you can see what was really sent,
all will probably become much clearer.

> And speaking of that, how I
> am to interpret 'character 201' -- should I collapse the SQL into it's
> minimal state (least number spaces) and go from that?

One character per character, whether that be a visible character or
whitespace (including newlines).  Collapsing out whitespace is
definitely not going to give you the right count.
        regards, tom lane


Re: parse error at or near "(" -- Huh???

From
Kenneth Gonsalves
Date:
On Monday 13 December 2004 08:15 am, Tom Lane wrote:
>
> One character per character, whether that be a visible character or
> whitespace (including newlines).  Collapsing out whitespace is
> definitely not going to give you the right count.

and while on this topic, how does one interpret the line numbers one gets 
when running psql -f to create tables?


Re: parse error at or near "(" -- Huh???

From
"D'Arcy J.M. Cain"
Date:
On Mon, 13 Dec 2004 09:27:04 +0530
Kenneth Gonsalves <lawgon@thenilgiris.com> wrote:
> and while on this topic, how does one interpret the line numbers one
> gets when running psql -f to create tables?

Forget about line numbers.  Add the -e option and your statements will
show up in your output.  Here is a sample (Unix) command line that I
commonly use to run statements from a file:

psql table -f in.file -e > out.file 2>&1

Now I can search the file for "ERROR" and see exactly what preceded it.

-- 
D'Arcy J.M. Cain <darcy@druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.


Re: parse error at or near "(" -- Huh???

From
Alex Beamish
Date:
On Sun, 12 Dec 2004 19:18:00 -0700, Michael Fuhr <mike@fuhr.org> wrote:
> On Thu, Dec 09, 2004 at 03:19:56PM -0500, Alex Beamish wrote:
> 
> > I'm getting a frustrating error
> >
> >   ERROR:  parser: parse error at or near "(" at character 201
> >
> > in a CREATE TABLE statement from an SQL script that I'm running from
> > within a Perl script. When I run the same script from the command
> > line, either as a regular user or as root, it works fine.
> 
> Your SQL statements ran fine for me, so please show us a small but
> complete Perl script that duplicates the problem.

Michael, Tom,

Thank you both for your responses .. I discovered that, while I was
editting what I thought was the running script, I was actually running
an earlier (wrong) version extracted a moment earlier from the version
control system, in a paralell directory. This became obvious when I
deleted the offending line and the error remained exactly the same.

However, I am intrigued to find out about the character offset that
appears in the error. How is that calculated? This would be useful
diagnostic information to have in the future.

Thanks!

Alex