Christopher Browne cbbrowne at ca.afilias.info
Fri Jul 6 08:32:00 PDT 2007
Darcy Buskermolen <darcyb at commandprompt.com> writes:

> On July 6, 2007 05:46 am, Dmitry Koterov wrote:
>> Hello.
>>
>> I feed the following syntax-correct query to slonik:
>>
>> CREATE RULE "position_get_last_id_on_insert" AS ON INSERT TO
>> "public"."position"
>> DO (SELECT currval('position_position_id_seq'::regclass) AS id;);
>>
>> And in pg logs I see:
>>
>> 2007-07-06 12:39:08 GMT 87.250.244.99(34424)ERROR:  syntax error at end of
>> input at character 149
>> 2007-07-06 12:39:08 GMT 87.250.244.99(34424)STATEMENT:
>>         CREATE RULE "position_get_last_id_on_insert" AS ON INSERT TO
>> "public"."position"
>>         DO (SELECT currval('position_position_id_seq'::regclass) AS id;
>>
>> Seems slonik treats intermediate ";" as a queries delimiter and splits
>> queries by it.
>> Possibly slonik should care about correct brackets nesting?
>
> How did you feed the to slonik?  slonik does not speek SQL, but is a interface 
> to the internal slon functions.

Regrettably, this looks like it is indeed a bug in the statement
parser in slonik.

If I add the following queries to the test set:
=========================================================
-- Here is a rule creation with an embedded semicolon

create table "public"."position";

CREATE RULE "position_get_last_id_on_insert"
AS ON INSERT TO "public"."position" DO (SELECT
currval('position_position_id_seq'::regclass) AS id;);
=========================================================

Here is the (relevant parts of) output from the scanner tester:

=========================================================

statement 14
-------------------------------------------



-- Here is a rule creation with an embedded semicolon

create table "public"."position";
statement 15
-------------------------------------------


CREATE RULE "position_get_last_id_on_insert2"
AS ON INSERT TO "public"."position" DO (SELECT
currval('position_position_id_seq'::regclass) AS id;
statement 16
-------------------------------------------
);%  
=========================================================

The statement is being split at the too-early semicolon.

This is evidently a bug.

I think it shouldn't be too difficult to add parenthesis counting to
the parser, but that won't help dmitry too soon or too easily.

There is, happily, a workaround to be offered; if the semicolon is
removed, the query should get processed as expected:

=========================================================
CREATE RULE "position_get_last_id_on_insert2"
AS ON INSERT TO "public"."position" DO (SELECT
currval('position_position_id_seq'::regclass) AS id);
=========================================================
-- 
let name="cbbrowne" and tld="ca.afilias.info" in name ^ "@" ^ tld;;
<http://dba2.int.libertyrms.com/>
Christopher Browne
(416) 673-4124 (land)


More information about the Slony1-general mailing list