Skip to content

Commit 769418a

Browse files
authored
Update integrating-with-databend-cloud-using-databend-sqlalchemy.md (#2470)
* Update integrating-with-databend-cloud-using-databend-sqlalchemy.md * Update integrating-with-databend-cloud-using-databend-sqlalchemy.md
1 parent 5fe186b commit 769418a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

docs/en/tutorials/programming/python/integrating-with-databend-cloud-using-databend-sqlalchemy.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,24 @@ pip install databend-sqlalchemy
1919
1. Copy and paste the following code to the file `main.py`:
2020

2121
```python
22-
from databend_sqlalchemy import connector
22+
from sqlalchemy import create_engine, text
23+
from sqlalchemy.engine.base import Connection, Engine
2324

2425
# Connecting to Databend Cloud with your credentials (replace PASSWORD, HOST, DATABASE, and WAREHOUSE_NAME)
25-
cursor = connector.connect(f"databend://cloudapp:{PASSWORD}@{HOST}:443/{DATABASE}?warehouse={WAREHOUSE_NAME}").cursor()
26-
cursor.execute('DROP TABLE IF EXISTS data')
27-
cursor.execute('CREATE TABLE IF NOT EXISTS data( Col1 TINYINT, Col2 VARCHAR )')
28-
cursor.execute("INSERT INTO data (Col1, Col2) VALUES (%s, %s), (%s, %s)", [1, 'yy', 2, 'xx'])
29-
cursor.execute("SELECT * FROM data")
30-
print(cursor.fetchall())
26+
engine = create_engine(
27+
f"databend://{username}:{password}@{host_port_name}/{database_name}?sslmode=disable"
28+
)
29+
cursor = engine.connect()
30+
cursor.execute(text('DROP TABLE IF EXISTS data'))
31+
cursor.execute(text('CREATE TABLE IF NOT EXISTS data( Col1 TINYINT, Col2 VARCHAR )'))
32+
cursor.execute(text("INSERT INTO data VALUES (1,'zz')"))
33+
res = cursor.execute(text("SELECT * FROM data"))
34+
print(res.fetchall())
3135
```
3236

3337
2. Run `python main.py`:
3438

3539
```bash
3640
python main.py
37-
[(1, 'yy'), (2, 'xx')]
38-
```
41+
[(1, 'zz')]
42+
```

0 commit comments

Comments
 (0)