2013-07-10 18 views
0

我有一个PostgreSQL 8.4数据库正在由我的控制之外的应用程序查询。查询如下面扔警告,但正在努力...PostgreSQL:非标准使用转义字符串

SELECT "tagname","tagindex","tagtype","tagdatatype" FROM "tagtable" WHERE "tagname" = 'Lift_Stations\07\ETMs\Generator_ETM' 

然而,对于站08和09相同的查询是失败...

SELECT "tagname","tagindex","tagtype","tagdatatype" FROM "tagtable" WHERE "tagname" = 'Lift_Stations\08\ETMs\Generator_ETM' 

WARNING: nonstandard use of escape in a string literal LINE 2: ...,"tagdatatype" FROM "tagtable" WHERE "tagname" = 'Lift_Stat... ^HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.

ERROR: invalid byte sequence for encoding "UTF8": 0x00 HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".

*** Error ***

ERROR: invalid byte sequence for encoding "UTF8": 0x00 SQL state: 22021 Hint: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".

我知道问题是不正确的转义,但鉴于08和09是唯一没有工作的事实,我希望有人可以有一个明智的想法,如何解决这个问题。

谢谢!

+0

'WHERE“tagname”= E'Lift_Stations \ 08 \ ETMs \ Generator_ETM''可以提供帮助。 – wildplasser

+0

如果不工作wildplasser的解决方案,请尝试添加另一个反斜杠,更多信息请阅读[此链接](http://stackoverflow.com/a/943/1563878)。 –

+0

@wildplasser我认为这是一条路径,他们不希望它被解释为转义序列。 –

回答

2

它应该工作,如果你enable standard_conforming_strings

+1

详细说明这个正确但简单的答案:较早的PostgreSQL版本用于让您在字符串中编写类似'\ n'的C风格转义。在新版本中,这已被默认关闭;这个警告告诉你,你在一个它仍然发生的版本。 –

+0

感谢@CraigRinger的帮助,总是很高兴在这里看到另一位2ndQ成员;) – Wolph

+0

我没有意识到你是在球队中。隐身。阿姆斯特丹......想知道那可能是谁;-)。真的应该在你的个人资料中提及2ndQ,如果做Pg相关社区的东西IIRC。 –