首页 > 解决方案 > 如何将整数值从 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 数据库?

标签: pythondjango

解决方案


推荐阅读