views:

33

answers:

2

While executing below shown trigger code using ANT I am getting the error

org.postgresql.util.PSQLException: ERROR: unterminated quoted string at or near "' DECLARE timeout integer" Position: 57

I am able to sucessfully execute the below code through PGADmin (Provided by postgres) and command line utility "psql" and the trigger function is added but while executing through ANT it fails everytime

BEGIN TRANSACTION;

CREATE OR REPLACE FUNCTION sweeper() RETURNS trigger as '
    DECLARE
    timeout integer;
    BEGIN
    timeout = 30 * 24 * 60 * 60 ;
        DELETE FROM diagnosticdata WHERE current_timestamp - teststarttime  > (timeout * ''1 sec''::interval);
        return NEW;
    END;
' LANGUAGE 'plpgsql';

-- Trigger: sweep on diagnosticdata

CREATE TRIGGER sweep
  AFTER INSERT
  ON diagnosticdata
  FOR EACH ROW
  EXECUTE PROCEDURE sweeper();

END;
A: 

I don't know what PostgreSql's escaping mechanism is, but try changing the quotes around:

(timeout * ''1 sec''::interval)

to

(timeout * "1 sec"::interval)
Mike Caron
A: 

Do yourself a favour - learn about dollar-quoted strings.

You'll find examples in the manual about writing functions (and trigger functions) with their help.

Milen A. Radev
Hi MilenI am aware of dollar quoted string but I still get similar error when i tried that
Anuj
What 'similar' error? I tried it here (had to improvise a bit because you didn't share the table definition) but it works fine.
Milen A. Radev