# Django Raw queryerror

**URL:** <https://forum.djangoproject.com/t/django-raw-queryerror/8057>\
**Category:** Using Django\
**Created:** [May 25, 2021, 1:25pm UTC](https://forum.djangoproject.com/t/django-raw-queryerror/8057 "2021-05-25T13:25:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![goncaloLopesMarques](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/goncalolopesmarques/32/4207_2.png) [@goncaloLopesMarques](https://forum.djangoproject.com/u/goncaloLopesMarques)\
**Post date:** [May 25, 2021, 1:25pm UTC](https://forum.djangoproject.com/t/django-raw-queryerror/8057/1 "2021-05-25T13:25:32Z")

</div>

Hi guys, i´m performing a bunch of raw querys to a sqlite database(the one who comes with the django). I tested the query in the data base browser and it works like a charm but when i tested it in views give me the “django.db.utils.OperationalError: near “?”: syntax error”

```
'> with connection.cursor() as cursor:
> cursor.execute(
> "select Count(point.id), areaTable.description " \
> "from indoorsite_point point " \
> "INNER JOIN indoorsite_tag as tag " \
> "ON point.tag_id = tag.id" \
> "INNER JOIN indoorsite_area as areaTable " \
> "ON areaTable.id = point.area_id " \
> "WHERE point.tag_id IN %s AND point.date BETWEEN %s AND %s " \
> "Group By point.area_id", [np.array(data["users"]), date, endDate]
> )
> row = cursor.fetchall()
> stats.append(row)'

```

I tried pass the array hardcoded in the string like " WHERE point.tag\_id IN (1,2,3)" and give me the following error “django.db.utils.ProgrammingError: Cannot operate on a closed cursor.”

Any suggestion?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 25, 2021, 2:05pm UTC](https://forum.djangoproject.com/t/django-raw-queryerror/8057/2 "2021-05-25T14:05:03Z")

</div>

> [@goncaloLopesMarques](#):
>
> ```auto
> > "INNER JOIN indoorsite_tag as tag " \
> > "ON point.tag_id = tag.id" \
> > "INNER JOIN indoorsite_area as areaTable " \
> >
> 
> ```

No idea if this is the specific issue or not, but I noticed how you have a space on the end of each line _except_ for the second line quoted above.

---

<div class="post-metadata">

**Author:** ![goncaloLopesMarques](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/goncalolopesmarques/32/4207_2.png) [@goncaloLopesMarques](https://forum.djangoproject.com/u/goncaloLopesMarques)\
**Post date:** [May 25, 2021, 2:40pm UTC](https://forum.djangoproject.com/t/django-raw-queryerror/8057/3 "2021-05-25T14:40:33Z")

</div>

Thanks for the reply, but i already change it but doesnt fix the issue =/

---

<div class="post-metadata">

**Author:** ![goncaloLopesMarques](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/goncalolopesmarques/32/4207_2.png) [@goncaloLopesMarques](https://forum.djangoproject.com/u/goncaloLopesMarques)\
**Post date:** [May 27, 2021, 9:19pm UTC](https://forum.djangoproject.com/t/django-raw-queryerror/8057/4 "2021-05-27T21:19:45Z")

</div>

I change sqlite to my sql and the bug go away -.-  
But now, every single query i do with cursor.execute(sql, params) give me empty results even SELECT \* FROM USER

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 27, 2021, 10:05pm UTC](https://forum.djangoproject.com/t/django-raw-queryerror/8057/5 "2021-05-27T22:05:10Z")

</div>

Can you repost your code block using the three backticks - ` before and after the code instead of the greater than - \> sign at the beginning of each line? It’s difficult to verify your indentation with that code posted like this.

---

<div class="post-metadata">

**Author:** ![goncaloLopesMarques](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/goncalolopesmarques/32/4207_2.png) [@goncaloLopesMarques](https://forum.djangoproject.com/u/goncaloLopesMarques)\
**Post date:** [June 16, 2021, 10:12am UTC](https://forum.djangoproject.com/t/django-raw-queryerror/8057/6 "2021-06-16T10:12:38Z")

</div>

Sorry for the late post, i switch sql lite for mysql and the error just disapear. So if anyone want to do raw querys my advice is to use a production database from the beginning
