📜  django 中的原始查询 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:06.841000             🧑  作者: Mango

代码示例1
from django.db import connection

sql = 'SELECT * FROM db1.a AS a
       JOIN db2.b AS b 
       ON b.some_id = a.id
       WHERE a.name = %s'
cursor = connection.cursor()
try:
      cursor.execute(sql, ['localhost'])
      row = cursor.fetchall()
except Exception as e:
      cursor.close