Psycopg2.ProgrammingError: cannot adapt type 'DictRow'

I want to use the dict pointer in psycopg2:

self.__db_conn = psycopg2.extras.DictConnection("host=... dbname=...")

here is my request:

cur.execute('INSERT INTO scm_main.tbl_ack(ack_summary_id, ack_local_timestamp, ack_user_id) '
    'SELECT summary_id AS ack_summary_id, now() AS ack_local_timestamp, us.user_id AS ack_user_id '
    'FROM scm_main.tbl_summary AS s '
    'INNER JOIN scm_main.vu_usr_stn AS us ON (s.summary_station_id = us.station_axis_id) '
    'WHERE ((s.summary_id > (SELECT COALESCE(max(a.ack_summary_id),0) FROM scm_main.tbl_ack AS a WHERE a.ack_user_id = %(user_id)s)) '
    'AND (s.summary_company_specific_id <> 0) '
    'AND (us.user_name = %(user_name)s) AND (s.summary_timestamp < (now() - \'00:25:00\'::interval))) '
    'ORDER BY s.summary_id ASC', { 'user_id': self.__user_id, 'user_name': self.__company })

But this gives me the following:

<class 'psycopg2.ProgrammingError'> exception: can't adapt type 'DictRow'

can anyone help?

+3
source share
1 answer

Complex types, such as DictRow(that is, a full row of results indexed by column name), cannot automatically adapt to simple SQL types, and psycopg just tells you that. Your code seems to be beautiful, so the error almost certainly lies in the fact that you want to put the query result in attributes self.__user_idand self.__company, but in the end put the whole set of results, i.e. DictRow, in one or both of them. Check out the code that retrieves the results.

+1
source

All Articles