Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL function definition in SQuirreL: unterminated dollar-quoted string

I have the following function definition for a PostgreSQL 9.3.4 database:

CREATE OR REPLACE FUNCTION update_modified_timestamp()  
RETURNS TRIGGER AS $$
  BEGIN
    NEW.modified_at = now();
    RETURN NEW; 
  END;
$$ LANGUAGE plpgsql;

When I try to execute this in SQuirreL (3.5.3 or 3.6), I get the following error:

Error: ERROR: unterminated dollar-quoted string at or near "$$
 BEGIN
     NEW.modified_at = now()"
  Position: 77
SQLState:  42601
ErrorCode: 0

So far I've learned this can be mitigated by using single quotes to delimit the function body like so:

CREATE OR REPLACE FUNCTION update_modified_timestamp()  
RETURNS TRIGGER AS '
  BEGIN
    NEW.modified_at = now();
    RETURN NEW; 
  END;
' LANGUAGE plpgsql;

Still I would like to know if this can't be solved otherwise - I think it must be possible since Flyway can execute this script and it uses the exact same JDBC driver that is configured in SQuirreL.


Update: @a_horse_with_no_name noted that this error has nothing to do with the JDBC driver, but with how SQuirreL parses the SQL statement and splits it into chunks before sending them to the database. Thus the remaining question is: Can SQuirreL send a query raw/unparsed? I've searched quite a bit couldn't find a way to do that.

like image 671
zb226 Avatar asked May 13 '15 09:05

zb226


1 Answers

You can change the statement separator so the statement is not split on a ;:

Go to: SessionSession PropertiesSQLStatement Separator

Even though you can't change it to an empty string, you can change it for example to //, which allows execution of the statement in the question.

like image 92
rubensa Avatar answered Oct 11 '22 11:10

rubensa