googleapis / googleapis/google-cloud-python

Add documentation on multi-statement queries

Đang mở
#15,771 1 bình luận 1 reaction 1 người được giao Được giao cho @chalmerlowe Xem trên GitHub
api: bigquery priority: p3 type: docs
Ngôn ngữ chính
Python
Star
5.4k
Fork
1.8k
Merge trung bình
3 ngày 4 giờ
Pull request đã merge (30 ngày)
122

Mô tả

**Is your feature request related to a problem? Please describe.**
I'm unsure how to make the best use of the library. Say I have a query like:
```sql
CREATE TEMP TABLE matching_foos AS (
SELECT foo_table.name, foo_table.id FROM foo_table
WHERE foo_table.name LIKE "%123%"
);
SELECT matching_foos.name, matching_foos.id
FROM matching_foos;
```

It's my understanding that as of googleapis/python-bigquery-sqlalchemy#74 it's possible to execute this multi-statement query. But, I can't figure out how to *build* such a query using sqlalchemy statements. e.g. if I have

```py
def get_matching_foos_query() -> sqlalchemy.selectable:
return sqlalchemy.select(models.foo_table.c.name, models.foo_table.c.id).where(models.foo_table.c.name.like("%123%"))
```

How would I then turn that into a temp table and then reference that table? Do I have to do a literal compile and then throw it into a sqlalchemy.text? Is there any sqlalchemy-style invocation to support this use case using similar `.c.column_a` syntax?

**Describe the solution you'd like**
Documentation (in the main README perhaps? or a link to a test file?) demonstrating how to create pythonic multi-statement queries that leverage some amount of modularity (vs straight text). Ideally would love to see: `CREATE TEMP TABLE` and `SET`/`DECLARE`
**Describe alternatives you've considered**
I really want to avoid just sending text. Doing so loses all of sqlalchemy's power to create modular statements by reusing filters, selectables, etc.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.