我在PSQL的函數是:如何在Python中投射Postgres參數?
CREATE OR REPLACE FUNCTION "xx"."xx"(IN cookieuserid int8, IN countryid varchar, IN federalregionid varchar,
IN regionid varchar, IN cityid varchar, IN rubric int4,
IN width int2, IN height int2, IN minbidprice numeric,
IN currentbid numeric, IN allowflash bool, IN allowgoods bool,
IN allowteasers bool, IN ismobileoptimized bool,
IN rtbactivesiteid int8, IN os varchar, IN sitestate int4,
IN bestrubricid int4)
我送參數在Python這樣的:
banner = yield self.db.execute('SELECT xx.xx
(%s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);',
(cookie_user_id, geoli[0], geoli[1], geoli[2], geoli[3], site[4],
banner_width, banner_height, min_bid_floor, ad_place[4], allow_flash,
allow_goods, allow_teasers, is_mobile_optimized, site[0], os, site[1], 0))
執行後,我得到了錯誤:
function whis2011.getrtbjsflashbannerinfomultysize(integer, integer, integer,
integer, integer, integer, integer, integer, integer, numeric, boolean, boolean,
boolean, boolean, integer, unknown, integer, integer) does not exist
LINE 1: SELECT whis2011.GetRtbJsFlashBannerInfoMultySize(1, 69, 1271...
^
提示:沒有函數匹配給定的名稱和參數類型。您可能需要添加顯式類型轉換。
這是正確的方法,即使是不同的類型,它仍然應該是'%s'。你的問題是你傳遞的一個類型與函數期望的不匹配。 –
你不應該這樣做:',\'%s \','。如果它作爲字符串傳入,它將在PostgreSQL執行之前被賦予適當的引號。 – Nicarus
我試過沒有\'%s \',那麼我得到的列「mac」不存在 LINE 1:... 0,0.000000,False,True,True,False,11145836,mac,2,0)... – Nikito