M
M
Murad Nurmagomedov2018-02-16 00:42:31
Python
Murad Nurmagomedov, 2018-02-16 00:42:31

Numpy and database queries?

Getting familiar with the numpy library. I tried to make a simple script for collecting data from the database. For some reason it gives an error:

TypeError: 'numpy.int32' object does not support indexing

The script itself:
import psycopg2
import numpy as np

selectDealersSQL = "SELECT dealer_id, name FROM public.dealers"
selectCountPointsSQL = 'SELECT count(*) FROM dealer_points WHERE point_type IN (1,2) AND active = TRUE AND dealer_id = %s'

conn = psycopg2.connect("dbname='***' user='nmurad' host='***.***.***.***' password='***'")
cur = conn.cursor()
cur.execute(selectDealersSQL)
rows = cur.fetchall()

points = np.array([], dtype='int8')

for row in rows:
    points = np.append(points, row[0])

for point in points:
    cur.execute(selectCountPointsSQL, point)

It gives the following error:

TypeError Traceback (most recent call last)
in ()
16
17 for point in points:
---> 18 cur.execute(selectCountPointsSQL, point)
TypeError: 'numpy.int32' object does not support indexing

Please help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question