Question: I wanted to perform an operation where i would like to delete all the rows(but not to drop the table) in postgres and update with new rows in it. And I wanted to use `pd.read_sql_query()` method from pandas:

```
qry = 'delete from "table_name"'
pd.read_sql_query(qry, conection, **kwargs)

```

But it was throwing error `'ResourceClosedError: This result object does not return rows. It has been closed automatically.'`

I can expect this because the method should return the empty dataframe.But it was not returning any empty dataframe but only the the above error. Could you please help me in resolving it??

Answer: 
I use MySql, but the logic is the same:

Query 1: Choose all ids from you table

Quear 2: Delete all this ids

As a result you have:

`Delete FROM table_name WHERE id IN (Select id FROM table_name)`

The line do not return anuthing, it just delete all rows with a special id. I recomend to do the command using psycopg only - no pandas.

Then you need another query to get smth from db like:

`pd.read_sql_query("SELECT * FROM table_name", conection, **kwargs)`

Probably (I do not use pandas to read from db) in this case you'll get empty dataframe with Column names

Probably you can combine all the actions, the following way:

`pd.read_sql_query('''Delete FROM table_name WHERE id IN (Select id FROM table_name); SELECT * FROM table_name''', conection, **kwargs)`

Please try and share your results.
**You can follow the next steps!**

1. Check 'row existence' first in the table.
2. And then delete rows

**Example code**

```
check_row_query = "select exists(select * from tbl_name limit 1)"
check_exist = pd.read_sql_query(check_row_query, con)
if check_exist.exists[0]:
    delete_query = 'DELETE FROM tbl_name WHERE condtion(s)'
    con.execute(delete_query) # to delete rows using a sqlalchemy function
    print('Delete all rows!)
else:
    pass

```