PostgreSQL function definition in SQuirreL: unterm

2020-02-01 04:12发布

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条回答
别忘想泡老子
2楼-- · 2020-02-01 04:13

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.

查看更多
登录 后发表回答