批处理文件:将%字符转义为PostgreSQL查询
问题描述:
我需要将%
字符转换为SQL查询,并将其传递给Windows批处理文件。我的问题是这个角色没有被考虑在内。批处理文件:将%字符转义为PostgreSQL查询
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><"C:\Program Files\PostgreSQL\9.4\bin\pgsql2shp.exe" -h localhost -u thomas -P password thomas_db "SELECT * FROM schema.table WHERE code like '12232'"> Initializing... ERROR: Could not determine table metadata
的LIKE '%%a%'
被解释为LIKE '12232'
和应为LIKE '12232%'
。
'喜欢 '%#%一%' 逃跑 '#'' – jarlh