Search Postgresql Archives

PL/Python error fetching next item from iterator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello All
I have problem when running PL/Python code in my customer machine, the python code run well on my dev machine.

My Dev machine PostgreSQL 9.0.6, compiled by Visual C++ build 1500, 64-bit, Python 2.6 (r26:66721, Oct  2 2008, 11:06:43) [MSC v.1500 64 bit (AMD64)] on win32, pyodbc-2.1.11.win-amd64-py2.6
My Customer machine  PostgreSQL 9.0.8, compiled by Visual C++ build 1500, 64-bit Python 2.6 (r26:66721, Oct  2 2008, 11:06:43) [MSC v.1500 64 bit (AMD64)] on win32, pyodbc-2.1.11.win-amd64-py2.6

Here is my 2 function

CREATE TYPE dmkh_return AS
   (ma_kh character varying,
    ten_kh character varying,
    ten_kh2 character varying,
    dia_chi character varying,
    ma_so_thue character varying,
    loai_kh smallint,
    nh_kh1 character varying,
    nh_kh2 character varying,
    nh_kh3 character varying,
    status character varying);
ALTER TYPE dmkh_return OWNER TO postgres;


CREATE OR REPLACE FUNCTION list_khachhang()
  RETURNS SETOF dmkh_return AS
$BODY$
import pyodbc
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=127.0.0.1,2205;DATABASE=TEST;UID=itg;PWD=')
dbcursor = cnxn.cursor()
dbcursor.execute("select ma_kh, dbo.ff_v2u(ten_kh) as ten_kh, '' as ten_kh2, '' as dia_chi, '' as ma_so_thue, CASE WHEN loai_kh IS NULL THEN 0 ELSE loai_kh END as loai_kh, nh_kh1, nh_kh2, nh_kh3, '1' as status from dmkh")
rows = dbcursor.fetchall()
for row in _rows:
yield row
$BODY$
  LANGUAGE plpythonu VOLATILE
  COST 100
  ROWS 1000;
ALTER FUNCTION list_khachhang() OWNER TO postgres;

==================

CREATE TYPE dmdv_return AS
   (ma_dv character varying,
    ten_dv character varying,
    ten_dv2 character varying,
    nh_dv1 character varying,
    nh_dv2 character varying,
    nh_dv3 character varying,
    status character varying);
ALTER TYPE dmdv_return OWNER TO postgres;

CREATE OR REPLACE FUNCTION list_dichvu()
  RETURNS SETOF dmdv_return AS
$BODY$
import pyodbc
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=127.0.0.1,2205;DATABASE=TEST;UID=itg;PWD=')
dbcursor = cnxn.cursor()
dbcursor.execute("select ma_dv, dbo.ff_v2u(ten_dv) as ten_dv, dbo.ff_v2u(ten_dv2) as ten_dv2, nh_dv1, nh_dv2, nh_dv3, '1' as status from dmdv")
rows = dbcursor.fetchall()
for row in rows:
yield row
$BODY$
  LANGUAGE plpythonu VOLATILE
  COST 100
  ROWS 1000;
ALTER FUNCTION list_dichvu() OWNER TO postgres;
====================

When i run 
SELECT * FROM list_dichvu() : It is Ok

But error happen when I run
SELECT *  FROM list_khachhang()

ERROR:  error fetching next item from iterator
CONTEXT:  PL/Python function "list_khachhang"


********** Error **********

ERROR: error fetching next item from iterator
SQL state: 22000
Context: PL/Python function "list_khachhang"


How to fix error. Please help me. Thanks in advance. Sorry for my English

Tuan Hoang Anh



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux