python - 如何将整数值从 python 转换为 smallint postgresql?
问题描述
我在 Postgresql 数据库中编写了一个函数,并且必须从 Python 的 Django 视图中调用它。该函数具有 smallint 类型的参数。在 Python 中,它看起来像
str = "02"
plist = [int(str)]
cursor = connection.cursor()
cursor.execute("select * from some_func(%s);", plist)
for row in cursor.fetchall():
...
在我的 HTML 模板中调用此代码我看到以下消息: function some_function(integer) does not exist 那是因为参数的类型是 smallint 我应该如何转换我的字符串以便将其作为 smallint 传递到 Postgresql 数据库?
解决方案
推荐阅读
- python - pandas select_dtypes 不返回所有 dtype 列
- android - Android Room:按自定义日期返回行,即 -7day 等
- nuxt.js - 如何安装@nuxtjs/auth 的测试版?
- python - 我将如何从网站上抓取数据并每天使用新信息更新文件,同时保存旧数据?
- python - 发生异常:将带有上下文的底图添加到 GeoPandas 地图时出现 SSLError
- ruby-on-rails - 检查 ActiveRecord::Relation 是否已经包含 JOIN
- c++ - 我如何确定一个函数是虚拟的,什么时候不是?
- c++ - 当它不可能工作时,static_cast 似乎工作
- python - 根据给定键的值唯一性删除字典列表中的重复字典
- apache-kafka - 使用 groupByKey/windowedBy/count 对 Kafka 流进行单元测试