betodealmeida commented on PR #30903:
URL: https://github.com/apache/superset/pull/30903#issuecomment-2532291633
> What will happen if I accidently make a change to a query which will
result in zero rows returned - all columns including metadata will be
permanently removed?
It should be fine, since the cursor should still return a description of the
columns even if the number of rows is 0. For example, for Postgres:
```python
import psycopg2
query = "SELECT * FROM your_table WHERE 1=0;" # Query guaranteed to return
zero rows
db_config = {
"dbname": "DB",
"user": "user",
"password": "password",
"host": "host",
"port": 5432,
}
with psycopg2.connect(**db_config) as conn:
with conn.cursor() as cursor:
cursor.execute(query)
print("Cursor description:")
for col in cursor.description:
print(
f"Name: {col.name}, Type: {col.type_code}, Display Size:
{col.display_size}"
)
```
For a test table this prints:
```
Cursor description:
Name: show_id, Type: 25, Display Size: None
Name: type, Type: 25, Display Size: None
Name: title, Type: 25, Display Size: None
Name: director, Type: 25, Display Size: None
Name: country, Type: 25, Display Size: None
Name: date_added, Type: 25, Display Size: None
Name: release_year, Type: 23, Display Size: None
Name: rating, Type: 25, Display Size: None
Name: duration, Type: 25, Display Size: None
Name: listed_in, Type: 25, Display Size: None
Name: description, Type: 25, Display Size: None
Name: iso_date_added, Type: 25, Display Size: None
Name: iso_release_year, Type: 25, Display Size: None
Name: xata_version, Type: 23, Display Size: None
Name: xata_createdat, Type: 1184, Display Size: None
Name: xata_updatedat, Type: 1184, Display Size: None
Name: xata_id, Type: 25, Display Size: None
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]