【问题标题】:Batch file: escape a % character into a PostgreSQL query批处理文件:将 % 字符转义到 PostgreSQL 查询中
【发布时间】:2016-02-29 13:12:24
【问题描述】:

我需要在 SQL 查询中使用 % 字符,然后将其传递到 Windows 批处理文件中。我的问题是没有考虑到这个字符。

towns=(12232, 12233)

for %%a in %towns% do (

    "C:\Program Files\PostgreSQL\9.4\bin\pgsql2shp.exe" -h localhost -u thomas -P  password thomas_db "SELECT * FROM schema.table WHERE code like '%%a%'"

)

我收到以下错误:

C:\batch> 正在初始化... 错误:无法确定表元数据

LIKE '%%a%' 被解释为LIKE '12232',应为LIKE '12232%'

【问题讨论】:

  • like '%#%a%' escape '#'

标签: sql postgresql batch-file escaping


【解决方案1】:

双百分号转义百分号,所以加倍:

... WHERE code like '%%a%%%'"

【讨论】:

    猜你喜欢
    • 2018-01-21
    • 1970-01-01
    • 2010-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多