Page 1 of 1

PostgreSQL: SQL statement doesn't return rows

Posted: Mon 01 Jun 2015 14:26
by ron.dunn
I'm trying to execute the following PostgreSQL command through PyODBC:

dw_cur.execute ("copy load_abc from 'c:/landing_zone/abc.csv' with (format csv,header TRUE)")

PyODBC is throwing an exception with the message "SQL statement doesn't return rows". I believe this comes from the driver.

My connection string is:

'Driver={Devart ODBC Driver for PostgreSQL};Server=XXX;Database=XXX;Username=XXX;Password=XXX;UseUnicode=1'

Any suggestions?

Re: PostgreSQL: SQL statement doesn't return rows

Posted: Mon 01 Jun 2015 14:42
by ron.dunn
Here is the relevant section of an ODBC trace:

Code: Select all

XXX d00-b20	ENTER SQLExecDirectW 
		HSTMT               0x00000000039917A0
		WCHAR *             0x0000000002E16D50 [      -3] "copy load_abc from 'c:/landing_zone/abc.csv' with (format csv,header TRUE)\ 0"
		SDWORD                    -3

XXX d00-b20	EXIT  SQLExecDirectW  with return code -1 (SQL_ERROR)
		HSTMT               0x00000000039917A0
		WCHAR *             0x0000000002E16D50 [      -3] "copy load_abc from 'c:/landing_zone/abc.csv' with (format csv,header TRUE)\ 0"
		SDWORD                    -3

		DIAG [HY000] [Devart][ODBC][PostgreSQL]SQL statement doesn't return rows (52032928) 

XXX d00-b20	ENTER SQLGetDiagRecW 
		SQLSMALLINT                  3 <SQL_HANDLE_STMT>
		SQLHANDLE           0x00000000039917A0
		SQLSMALLINT                  1 
		SQLWCHAR *          0x0000000000BDF320
		SQLINTEGER *        0x0000000000BDF838
		SQLWCHAR *          0x0000000003991DF0 
		SQLSMALLINT               1023 
		SQLSMALLINT *       0x0000000000BDF830

XXX d00-b20	EXIT  SQLGetDiagRecW  with return code 0 (SQL_SUCCESS)
		SQLSMALLINT                  3 <SQL_HANDLE_STMT>
		SQLHANDLE           0x00000000039917A0
		SQLSMALLINT                  1 
		SQLWCHAR *          0x0000000000BDF320 [       5] "HY000"
		SQLINTEGER *        0x0000000000BDF838 (0)
		SQLWCHAR *          0x0000000003991DF0 [      59] "[Devart][ODBC][PostgreSQL]SQL statement doesn't return rows"
		SQLSMALLINT               1023 
		SQLSMALLINT *       0x0000000000BDF830 (59)


Re: PostgreSQL: SQL statement doesn't return rows

Posted: Wed 03 Jun 2015 13:01
by AlexP
We can't reproduce the issue. The copy command is executed with no errors on the latest driver version 1.1.1. Please specify the driver version and the version of Python and PyODBC.

Code: Select all

Python 3.3.5 (v3.3.5:62cf4e77f785, Mar  9 2014, 10:37:12) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
>>> import pyodbc
>>> con = pyodbc.connect('DSN=test_postgres')
>>> cur = con.cursor()
>>> cur.execute("copy emp from 'd:\emp.csv'");
<pyodbc.Cursor object at 0x02A4A0C8>
>>> con.commit()
>>>