SQuirreL中的PostgreSQL函数定义:未终止的美元引用字符串

时间:2021-02-08 23:08:31

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

我有一个PostgreSQL 9.3.4数据库的以下函数定义:

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:

当我尝试在SQuirreL(3.5.3或3.6)中执行此操作时,我收到以下错误:

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.

我仍然想知道这是否无法解决 - 我认为必须可行,因为Flyway可以执行此脚本并且它使用在SQuirreL中配置的完全相同的JDBC驱动程序。


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.

更新:@a_horse_with_no_name指出此错误与JDBC驱动程序无关,而是与SQuirreL如何解析SQL语句并在将它们发送到数据库之前将其拆分为块。因此剩下的问题是:SQuirreL可以发送原始/未解析的查询吗?我搜索了很多,找不到办法做到这一点。

1 个解决方案

#1


6  

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

您可以更改语句分隔符,以便不将语句拆分为;:

Go to: SessionSession PropertiesSQLStatement Separator

转至:会话→会话属性→SQL→语句分隔符

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.

即使您无法将其更改为空字符串,也可以将其更改为例如//,这样可以在问题中执行语句。

#1


6  

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

您可以更改语句分隔符,以便不将语句拆分为;:

Go to: SessionSession PropertiesSQLStatement Separator

转至:会话→会话属性→SQL→语句分隔符

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.

即使您无法将其更改为空字符串,也可以将其更改为例如//,这样可以在问题中执行语句。