https://github.com/alvations/dopplershift
Pythonic SQL for mere mortals
https://github.com/alvations/dopplershift
python redshift sql
Last synced: about 2 months ago
JSON representation
Pythonic SQL for mere mortals
- Host: GitHub
- URL: https://github.com/alvations/dopplershift
- Owner: alvations
- License: mit
- Created: 2019-08-21T06:14:40.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-03T19:22:13.000Z (almost 7 years ago)
- Last Synced: 2025-10-05T20:14:35.147Z (9 months ago)
- Topics: python, redshift, sql
- Language: Python
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dopplershift
Pythonic SQL for mere mortals.
# Install
```
pip install -U dopplershift
```
# Usage
```python
from dopplershift import Connection
host = 'rayleigh.3onystnrm1rn.us-east-1.redshift.amazonaws.com'
dbname = 'testing'
port = '1234'
user = 'alvations'
pwd = 'JjMKkdW8vJABswyT'
con = Connection(dbname, host, port, user, pwd)
```
### Show all schemas and tables in DB.
```python
con.show_all_tables()
```
[out]:
```
table_schema | table_name
--------------+----------------
testing | data
stagging | results
production | results
```
### Show columns in specific table.
```python
con.show_column_names('testing.data')
```
[out]:
```
view_schema name | view_name name | col_name name | col_type varchar | col_num int
---------------------------------------------------------------------------------------------------
testing | data | id | integer | 1
testing | data | text | character varying(1024) | 2
testing | data | language | character varying(3) | 4
testing | data | timestamp | timestamp without time zone | 5
```
### Other Functions.
```python
# Get column names.
>>> con.get_column_names('testing.data')
('id', 'text', 'language', 'timestamp')
# Get top N rows from table.
>>> con.topn_rows('testing.data', n=3, column_names="id, text, language")
[(1, "hello world", "en"), (2, "hallo welt", "de"), (3, "你好,世界。", "zh")]
# Execute queries and fetch results.
>>> con.execute_fetchall("SELECT TOP 2 * FROM testing.data")
[ (1, "hello world", "en", datetime.datetime(2019, 9, 2, 14, 5, 58)),
(2, "hallo welt", "de", datetime.datetime(2019, 9, 2, 14, 6, 15)) ]
```