Page 1 of 1

Spurious sytax error with INSERT

Posted: Mon Sep 09, 2019 4:53 pm
by HughDarwen
Try this:

var x base relation{z char} key{z};
insert x extend TABLE_DEE : {z := '//'};

I get
ERROR: Encountered "insert" at line 1, column 1.

Was expecting one of:
"BEGIN" ...
"TCLOSE" ...
<TUPLE> ...
"WITH" ...
<TUPLE> ...

I have used a bypass of this kind sometimes:

x := (extend TABLE_DEE : {z := '//'}) union x;

but it doesn't work with this particular example.

The problem seems to arise only with multiple successive slashes in quotes.

Hugh

Re: Spurious sytax error with INSERT

Posted: Sat Sep 21, 2019 11:43 am
by Dave
I'll do some tests on this to see if I can find a workaround. I know EXTEND can expose a grammar ambiguity (I don't recall the specifics, but I know it does) and this is likely related to it.

Re: Spurious sytax error with INSERT

Posted: Sat Sep 21, 2019 12:20 pm
by Dave
I see the problem -- it's with the mechanism in the DBrowser front-end that tries to detect whether you've entered an expression or one or more statements. It's surprisingly complex and it can be fooled. In this case, it's being fooled into thinking you've entered an expression by the slashes '//', which it thinks are a comment token and so it ignores the rest of the line.

A simple workaround is to force the front-end to treat your statement(s) as an expression, using a Rel extension for that purpose. You surround the statements with a BEGIN ... END block, followed by an expression. Like this:

Code: Select all

begin;
	var x base relation {z char} key {z};
	insert x extend TABLE_DEE : {z := '//'};
end;
true

Re: Spurious sytax error with INSERT

Posted: Sun Sep 22, 2019 2:11 pm
by HughDarwen
Thank you. I like your suggested bypass because since I posted this problem I've been surrounding the code with begin/end for other reasons. My own bypass had been to use direct assignment: x := (extend TABLE_DEE <etc.>) union x;

Hugh