Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9c23804

Browse filesBrowse files
author
Ilya Gurov
authored
docs: add query hints example (googleapis#153)
1 parent c4629f3 commit 9c23804
Copy full SHA for 9c23804

File tree

Expand file treeCollapse file tree

1 file changed

+23
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+23
-0
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,29 @@ eng = create_engine("spanner:///projects/project-id/instances/instance-id/databa
157157
autocommit_engine = eng.execution_options(isolation_level="AUTOCOMMIT")
158158
```
159159

160+
### Query hints
161+
Spanner dialect supports [query hints](https://cloud.google.com/spanner/docs/query-syntax#table_hints), which give the ability to set additional query execution parameters. Usage example:
162+
```python
163+
session = Session(engine)
164+
165+
Base = declarative_base()
166+
167+
class User(Base):
168+
"""Data model."""
169+
170+
__tablename__ = "users"
171+
id = Column(Integer, primary_key=True)
172+
name = Column(String(50))
173+
174+
175+
query = session.query(User)
176+
query = query.with_hint(
177+
selectable=User, text="@{FORCE_INDEX=index_name}"
178+
)
179+
query = query.filter(User.name.in_(["val1", "val2"]))
180+
query.statement.compile(session.bind)
181+
```
182+
160183
### ReadOnly transactions
161184
By default, transactions produced by a Spanner connection are in ReadWrite mode. However, some applications require an ability to grant ReadOnly access to users/methods; for these cases Spanner dialect supports the `read_only` execution option, which switches a connection into ReadOnly mode:
162185
```python

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.