用美元结尾的不加引号的字符串

用美元结尾的不加引号的字符串

本文介绍了SQuirreL中的PostgreSQL函数定义:用美元结尾的不加引号的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于PostgreSQL 9.3.4数据库,我具有以下函数定义:

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;

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

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;

我仍然想知道这是否可以通过其他方式解决-我认为这必须可行,因为空中通道可以执行此脚本,并且它使用与SQuirreL中配置的完全相同的JDBC驱动程序.

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.

更新: @a_horse_with_no_name 指出此错误与JDBC驱动程序无关,但与SQuirreL如何解析SQL语句并将其拆分为大块然后发送它们有关到数据库.因此剩下的问题是: 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.

推荐答案

您可以更改语句分隔符,以使语句不会在;上拆分:

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

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

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.

这篇关于SQuirreL中的PostgreSQL函数定义:用美元结尾的不加引号的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 13:34