Small, non-urgent question about .fetchall()

I’m working on the Dataquest Advanced SQL course, and the final two missions of the course have been working on creating indexes. There seems to be inconsistency in the Answers provided about whether .fetchall() is included at the end of the CREATE INDEX commands; sometimes it’s there (e.g., https://app.dataquest.io/m/117/multi-column-indexing/3/query-plan-for-multi-column-queries), sometimes it’s not (e.g., https://app.dataquest.io/m/117/multi-column-indexing/6/creating-a-multi-column-index), and I can’t figure out what makes the difference. Is it optional?

2 Likes

hey @dlsmeltzer

Interesting question! Even I don’t fully comprehendthis, but the below SO post might help you somewhat.

2 Likes

Hi @dlsmeltzer,

As per my understanding, .fetchall() is required only when we need to fetch data using select statement.

1 Like

I think the answer is that the person or people who are creating the answer code aren’t consistent in their decision to use fetchall() on queries that return no results and/or where the results are discarded.

1 Like

Hi @eas-sea @dlsmeltzer,

@sreekanthac is right here. .fetchall() is only requires if your query returns rows. If we use it for queries like CREATE, it will just end up returning an empty list as there is nothing to fetch. I will get it logged as the solution is incorrect here.

Best,
Sahil

2 Likes