Обсуждение: plpython integer types
Hi everibody, a plpython function i'm writing fail with a strange ( to me ) message error: ..... plan=ply.prepare("intert into text,text1,integer1,text" values($1,$2,$3,$4)",["text","text","integer","text"]) ply.execute(plan,[var1,var2,var3,var4]) ..... The backend raise an errore saying: ERROR: type integer does not exist... I can't understand this.... How can i solve this problem, or, say, how can I cast python variables?
Emiliano Amilcarelli <amiemi@tin.it> writes: > a plpython function i'm writing fail with a strange ( to me ) message error: > ..... > plan=ply.prepare("intert into text,text1,integer1,text" > values($1,$2,$3,$4)",["text","text","integer","text"]) > ply.execute(plan,[var1,var2,var3,var4]) > ..... > The backend raise an errore saying: > ERROR: type integer does not exist... Does it work if you say "int4" instead? regards, tom lane
No, it doesn,'t work if i use int4 I solved the problem casting the type: plan=plpy.prepare("INSERT INTO \"tmp_test\"(\"AGENT\",\"ERRORE\",\"PROVE_FALLITE\",\"DATA_ORA_ACCESSO\") values($1,$2,$3::int,$4)",["text","text","text","text"]) Thanks for help.... Regards. Emil Tom Lane ha scritto: > Emiliano Amilcarelli <amiemi@tin.it> writes: > >> a plpython function i'm writing fail with a strange ( to me ) message error: >> > > >> ..... >> plan=ply.prepare("intert into text,text1,integer1,text" >> values($1,$2,$3,$4)",["text","text","integer","text"]) >> ply.execute(plan,[var1,var2,var3,var4]) >> ..... >> > > >> The backend raise an errore saying: >> ERROR: type integer does not exist... >> > > Does it work if you say "int4" instead? > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster >
On Thu, Nov 17, 2005 at 03:46:46PM +0100, Emiliano Amilcarelli wrote: > No, it doesn,'t work if i use int4 int4 works for me in PostgreSQL 8.1.0 and 8.0.4: CREATE TABLE foo ( i integer, f float8, n numeric, t text, d date ); CREATE FUNCTION populate() RETURNS boolean AS $$ query = 'INSERT INTO foo (i, f, n, t, d) VALUES ($1, $2, $3, $4, $5)' types = ('int4', 'float8', 'numeric', 'text', 'date') plan = plpy.prepare(query, types) plpy.execute(plan, (1, 2.3, 4.56, 'test', '2005-11-17')) return True $$ LANGUAGE plpythonu VOLATILE; SELECT populate(); populate ---------- t (1 row) SELECT * FROM foo; i | f | n | t | d ---+-----+------+------+------------ 1 | 2.3 | 4.56 | test | 2005-11-17 (1 row) -- Michael Fuhr