Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- conn = psycopg2.connect("dbname=postgres user=postgres password=psswd")
- cur = conn.cursor()
- cur.copy_to(sys.stdout,'mytable',sep = 't')
- E0307 1 M 400 Ethan UTDallas 12.98580404 N 50.79403657 1
- E0307 1 M 400 Lucas Baylor 15.18511175 N 56.87285183 3
- E0307 1 M 400 Jackson Baylor 13.64228411 N 56.87285183 3
- E0307 1 M 400 Jacob Baylor 13.19878974 N 56.87285183 3
- E0307 1 M 400 Samuel Baylor 14.84666623 N 56.87285183 3
- ProgrammingError: can't execute COPY TO: use the copy_to() method instead
- import psycopg2 as pg
- import pandas as pd
- import pandas.io.sql as psql
- connection = pg.connect("dbname=postgres user=postgres password=psswd")
- #my_table = pd.read_sql_table('table_name', connection)
- my_table = pd.read_sql('select * from my-table-name', connection)
- another_attempt= psql.read_sql("SELECT * FROM my-table-name", connection)
- print(my_table)
- # OR
- print(another_attempt)
- copy = "copy mytable to stdout with csv header delimiter 't' null 'NULL'"
- cursor.copy_expert(copy, sys.stdout)
- header = [i[0] for i in cur.description
- print header
- cur.copy_to(sys.stdout, 'table', sep='t', null='N')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement