- django中使用原生sql
? ? from django.db import? connection
? ?cursor = connection.cursor()
? ?cursor.execute("select * from xx where id=1")
? ?row = cursor.fetchone()
?
? ?users = User.objects.raw("select * from user where name='xx'")
? ?for user in users:
? ? ? ? ?? print(user.name)
查詢結果對應model
- sql 使用正則
? ? ? ? ?select * from user where name regexp 'a|b';
?