PostgreSQL function definition in SQuirreL: unterminated dollar-quoted string

拜拜、爱过 提交于 2019-11-26 21:34:37

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/30211053/postgresql-function-definition-in-squirrel-unterminated-dollar-quoted-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!