开发者

How to escape quotes in strings in vertica (vsql)?

开发者 https://www.devze.com 2023-02-13 01:54 出处:网络
So I need to insert some values开发者_如何学Python into a vertica database (via vsql), which may contain quotes and all sorts of special characters. But vertica does not seem to understand character e

So I need to insert some values开发者_如何学Python into a vertica database (via vsql), which may contain quotes and all sorts of special characters. But vertica does not seem to understand character escaping. For example:

rpt=> select "asdasda\"asdasdad" from some_table limit 1;
rpt"> ";
ERROR:  syntax error at or near "" from some_table limit 1;
"" at character 26
LINE 1: select "asdasda\"asdasdad" from some_table limit 1;

This is not the insert statement, but you should get the idea.


Well, first off I should have used single quotes. Escape sequences used to work in earlier versions (before 4.0 I believe), but now they are off by default. If you do not want to tweak database config parameters you have two options.

Use E' syntax:

select E'somethin\' here' from v_catalog.dual_p;

Or double the quotes that need to be escaped:

select 'somethin'' here' from v_catalog.dual_p;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号