【发布时间】:2017-06-07 00:16:34
【问题描述】:
我有以下 2 个 Python 代码:
def direct_by_node(self, node, partition_size):
return '''select req.id, req.profile_id as profile
from table1 attr
where id % {0} = {1}'''.format(partition_size, node)
然后
def find_by_node(self, node, partition_size):
return '''select req.id, req.profile_id as profile
from table1 attr
where id %% {0} = {1}'''.format(partition_size, node)
我想知道 2 个 MySQL 查询中的 % 和 %% 是关于什么的?
编辑:
当我在 MySQL Workbench 中尝试 %% 时,看起来我有语法错误,看起来 %% 无效。
【问题讨论】:
-
感谢@darnell,我看过这个,但我不完全确定它是否与我的相同,因为它类似于“%lastuser%”...
-
不要使用Python字符串格式化生成SQL查询字符串;使用您的库创建参数化查询的能力。