postgresql dollar引号在其中

发布于 2025-02-03 06:32:14 字数 324 浏览 2 评论 0原文

对于在PostgreSQL中的Where子句中尝试或需要解决方案的人来说,应如何使用。

文档可能很难理解,没有适当的例子,所以这里是我的

:如果您想提出一个请求,因为

SELECT
    *
FROM
    <TableName> 
WHERE
    <ColumnName> = 'string with ' character';

它会抛出错误原因,原因是“字符'”在字符串之外

For people who tried or needed a solution to escape every special character (even $) in a WHERE CLAUSE in POSTGRESQL, here is how it should be use

the documentation can be somehow hard to understand, and there is no proper example of it so here is mine

e.g : if you want to make a request looking as

SELECT
    *
FROM
    <TableName> 
WHERE
    <ColumnName> = 'string with ' character';

it will throw an error cause "character'" is outside the string

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缘字诀 2025-02-10 06:32:14

因此,这是应该写的:

SELECT
    *
FROM
    <TableName> 
WHERE
    <ColumnName> = $string with ' character$;

条件从字面上占用字符串;该界面看起来可能打破,但仍将按照预期解释以下指令。

SELECT
    *
FROM
    <TableName> 
WHERE
    <ColumnName> = $string with ' character$ AND <OtherColumnName> IS NOT NULL;

这甚至可能是$$的另一个逃脱字符串。

有关美元报价的详细信息,请查看文档

So here is how it should be written:

SELECT
    *
FROM
    <TableName> 
WHERE
    <ColumnName> = $string with ' character$;

The WHERE CONDITION will take the string literally; the interface may look broken but the following instruction will still be interpreted as expected.

SELECT
    *
FROM
    <TableName> 
WHERE
    <ColumnName> = $string with ' character$ AND <OtherColumnName> IS NOT NULL;

This could even be another escaped string with $$.

For details about dollar quoting, look at the documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文