Answer by klin for psycopg2 copy_to part of table
Use cursor.copy_expert(), place your query as an argument to COPY command, e.g.:sql = """ copy ( select * from my_table where id < 5 order by id ) to stdout"""with open('/data/my_file.txt', 'w') as...
View Articlepsycopg2 copy_to part of table
there is a copy_to to copy table data into file like:cursor.copy_to(fp, 'table_name')but I don't need to copy all table data, just a part of it.So when I do:cursor.execute(query)cursor.copy_to(fp,...
View Article
More Pages to Explore .....