Обсуждение: parser :parse error

Поиск
Список
Период
Сортировка

parser :parse error

От
"Frederic boucher"
Дата:
Hi,

I'm trying to create a table with a default value for a field that containt 
an 's ...  And the server always tell me :

Error : parser: parse error at or near "s"

my create looks like :

create table tablename ( thefield varchar(50) default 'Fred''s car'
);

Any suggestion?

PS:  This is more a linux question... but..  If I have a big file that 
contains all my sql to create my tables structure.  I want to run it by 
doing "\i filename"  but it scroll so fast I can't see when there is 
error... is there a way to do a kind of "pipe into less"

\fb

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com


Re: [SQL] parser :parse error

От
Bruce Momjian
Дата:
Works on current tree.  Try 6.5.3.


> Hi,
> 
> I'm trying to create a table with a default value for a field that containt 
> an 's ...  And the server always tell me :
> 
> Error : parser: parse error at or near "s"
> 
> my create looks like :
> 
> create table tablename (
>   thefield varchar(50) default 'Fred''s car'
> );
> 
> Any suggestion?
> 
> PS:  This is more a linux question... but..  If I have a big file that 
> contains all my sql to create my tables structure.  I want to run it by 
> doing "\i filename"  but it scroll so fast I can't see when there is 
> error... is there a way to do a kind of "pipe into less"
> 
> \fb
> 
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
> 
> ************
> 
> 


--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: [SQL] parser :parse error

От
Peter Eisentraut
Дата:
On 1999-11-08, Frederic boucher mentioned:

> Hi,
> 
> I'm trying to create a table with a default value for a field that containt 
> an 's ...  And the server always tell me :
> 
> Error : parser: parse error at or near "s"
> 
> my create looks like :
> 
> create table tablename (
>   thefield varchar(50) default 'Fred''s car'
> );
> 
> Any suggestion?

Try 'Fred\'s car'.

> 
> PS:  This is more a linux question... but..  If I have a big file that 
> contains all my sql to create my tables structure.  I want to run it by 
> doing "\i filename"  but it scroll so fast I can't see when there is 
> error... is there a way to do a kind of "pipe into less"

You can try \o outputfile, but I'm not sure if that works correctly. psql
has some problems in that regard. I fixed that in the new one, so if you
feel like pulling it from the current source. In particular, the new psql
lets you stop scripts on error.

But that new one is not completely bug free yet, of course.

On the other hand, what about this:
$ psql -f infile.sql -o outfile.txt
or
$ psql -f infile.sql > outfile.txt
or anything like that.

-- 
Peter Eisentraut                  Sernanders vaeg 10:115
peter_e@gmx.net                   75262 Uppsala
http://yi.org/peter-e/            Sweden



Re: [SQL] parser :parse error

От
"Moray McConnachie"
Дата:
> PS:  This is more a linux question... but..  If I have a big file that
> contains all my sql to create my tables structure.  I want to run it by
> doing "\i filename"  but it scroll so fast I can't see when there is
> error... is there a way to do a kind of "pipe into less"

psql -d database -c '\i filename' ¦ more



Re: [SQL] parser :parse error

От
Tom Lane
Дата:
[ sorry for not responding sooner, but I was on vacation... ]

>> create table tablename (
>> thefield varchar(50) default 'Fred''s car'
>> );
>> 
>> Error : parser: parse error at or near "s"

Bruce Momjian <maillist@candle.pha.pa.us> writes:
> Works on current tree.  Try 6.5.3.

It does work now, but is broken in 6.5.* and (AFAIK) all prior releases.
The problem is that the parser retranslates DEFAULT expressions into
source form after parsing them --- and the retranslation code is not
bright enough to provide quoting for embedded quotes and backslashes
in string constants.  So the system ends up trying to processDEFAULT 'Fred's car'
which obviously won't work.

Current sources fix this by eliminating the retranslation step.  That's
a pretty major change, so I don't think it's practical/safe to backpatch
it into 6.5.*.  If someone wants to fix this problem as a patch for
6.5.*, probably the best way to proceed would be to fix
backend/parser/gram.y's makeConstantList() to apply appropriate
backslash-quoting within string constants.  I don't have the time or
interest to do it myself though.
        regards, tom lane