mysql - Concat 函数在 Flask 上的 MySQL 查询中返回 1
问题描述
我MySql
在带有函数的烧瓶中运行查询,concat
它总是返回 1。
cur.execute("INSERT INTO jobs( job_id, job_name, company, who_created)
VALUES(%s,%s, %s,%s)",(job_id,job_name, company,
[cur.execute("select concat(first_name , ' ' , last_name)
from employees where username = %s", [username] ) ] ) )
who_created
总是返回1
。
当我在 MySQLWorkbench 上运行查询时,它工作正常并返回first name + last name
.
问题不在于 concat 函数,因为即使我在没有 concat 的情况下运行它,我也会收到“str object is not callable”错误
谢谢。
解决方案
cur.execute
将返回找到的行数。要获取返回的数据,您需要在执行后使用另一个调用:
cur.execute("select concat(first_name , ' ' , last_name) from employees where username = %s", [username] )
name_rs = cur.fetchall()
cur.execute("INSERT INTO jobs( job_id, job_name, company, who_created) VALUES(%s,%s,%s,%s)",(job_id, job_name, company, name_rs[0][0] ) )
推荐阅读
- c++ - 在调试模式下调用函数时,GDB 崩溃
- python - 一段代码中的麻烦 python getattr()
- c++ - UVA 10077 - 为什么是二进制搜索?
- java - SQLite 查询的空引用
- kotlin - 如何创建类型的 lambda ((KeyboardEvent) -> dynamic)?在科特林
- jquery - Laravel - 如何根据条件为动态输入字段指定行
- azure-devops - 如何将 TestNG 或范围报告与 Azure devops 集成?
- gradle - 如何在具有 android、iOS 和不受支持的目标(如 mingwX64)的 kotlin 多平台项目中设置 sqldelight?
- java - 压缩视频质量并上传到 firebase 无法压缩 mp4 视频的大小
- python - 在 Pandas Dataframe 上使用 groupby 按一列重新排列,最大值仅为另一列