Skip to content

Instantly share code, notes, and snippets.

@chaudum
Created May 4, 2018 06:48
Show Gist options
  • Save chaudum/4a4df482c1b025369aaa34e82215936f to your computer and use it in GitHub Desktop.
Save chaudum/4a4df482c1b025369aaa34e82215936f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
from datetime import datetime
from crate.client import connect
def main():
now = datetime.utcnow()
with connect('localhost:4200') as conn:
cur = conn.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS t2 (col_str STRING, col_long LONG, col_ts TIMESTAMP)')
cur.execute('INSERT INTO t2 (col_str, col_long, col_ts) VALUES (?, ?, ?)',
(now, now, now))
cur.execute('REFRESH TABLE t2')
cur.execute('SELECT col_str, col_long, col_ts FROM t2')
cols = [c[0] for c in cur.description]
for idx, val in enumerate(cur.fetchone()):
print('{} => {} ({})'.format(cols[idx], val,type(val)))
if __name__ == '__main__':
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment