如何将整数值从python转换为smallint postgresql?

如何将整数值从python转换为smallint postgresql?,python,django,Python,Django,我在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():

我在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模板中调用此代码时,我会看到以下消息: 函数某些函数(整数)不存在 这是因为参数的类型是smallint
我应该如何转换字符串以将其作为smallint传递到Postgresql数据库?

(int)str
无效,它应该是
int(str)
,(最好不要首先命名变量
str
)。事实上我有int(str)。这不完全是代码。代码更复杂。“函数某些函数(整数)不存在,这是因为参数的类型是smallint”;这是一个错误的结论。我想你需要做
plist[0]
,以便将int传递给
某个函数()
。我做了一个实验。在Postgresql中编写了一个函数,将输入参数从integer转换为smallint,并调用原始参数。这是有效的。