pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Olivier Hubaut <olivier@amaze.ulb.ac.be>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Parsing problem when launching SQL files with Ant (through
Date: Fri, 21 May 2004 19:52:03 +1200
Message-ID: <40ADB523.9010506@opencloud.com> (raw)
In-Reply-To: <opr7698vz71vnsxw@olivier.amaze.ulb.ac.be>
References: <opr7698vz71vnsxw@olivier.amaze.ulb.ac.be>

Olivier Hubaut wrote:
> Using
> - Ant 1.6.1
> - PostgreSQL 7.4.2
> - PostgreSQL 7.4.2 JDBC Driver
> 
> We detected that when launching SQL script files with Ant (using the 
> sql  task), a parsing problem occurs when those files contain comments.
> 
> We found a VERY ugly workaround: positionning the semi-colons at the  
> beginnig of the lines instead of the end.
> 
> [snippet]
> -- 
> -- This code does NOT work with this comment
> -- 
> CREATE FUNCTION foo.bar (VARCHAR(256))
>     RETURNS integer
>     LANGUAGE SQL
>     AS '
>         DELETE FROM foo.bar_table WHERE field = $1;
>         SELECT 1
>     '
> ;

By default, Ant's sql task uses ';' as a query delimiter (see the Ant 
manual). Also, Ant doesn't appear to check for string constants when 
breaking up the input file -- all semicolons are treated as delimiters 
regardless of where they occur. So this is being given to the driver as 
two queries:

query 1: CREATE FUNCTION foo.bar (VARCHAR(256)) RETURNS integer LANGUAGE 
SQL AS 'DELETE FROM foo.bar_table WHERE field = $1

query 2: SELECT 1'

and things break horribly.

If you specify a different delimiter via the delimiter attribute of the 
sql task, the above example works fine.

> [snippet]
> -- 
> -- This code works with this comment
> -- 
> CREATE FUNCTION foo.bar (VARCHAR(256))
>     RETURNS integer
>     LANGUAGE SQL
>     AS '
>     ; DELETE FROM foo.bar_table WHERE field = $1
>     ; SELECT 1'
> ;

I don't know why this works (it shouldn't!) -- but for some reason Ant 
submits this as a single query even with delimiter=";".

You can see the exact queries being submitted to the server by setting 
"log_statement = true" in postgresql.conf.

-O



view thread (2+ messages)

Message-ID: <40ADB523.9010506@opencloud.com>
Permalink:  ../40ADB523.9010506@opencloud.com/
Also on:    postgresql.org/message-id/40ADB523.9010506@opencloud.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: oliver@opencloud.com, olivier@amaze.ulb.ac.be
  Subject: Re: Parsing problem when launching SQL files with Ant (through
  In-Reply-To: <40ADB523.9010506@opencloud.com>
  References: <opr7698vz71vnsxw@olivier.amaze.ulb.ac.be> <40ADB523.9010506@opencloud.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox