sql - Postgresql: How to export tables into separate csv files -
i want export entire database aws s3 later import bi tools. need export each database table own csv file. dont wanna manually or script-fu. mysql have this. there easy way achieve postgresql?
with query can list tables in schema public
:
select table_schema, table_name information_schema.tables table_type = 'base table' , table_schema = 'public';
you can use query in function, execute appropriate copy
command each table_name:
create or replace function copy_my_tables () returns void language plpgsql $$ declare r record; begin r in select table_schema, table_name information_schema.tables table_type = 'base table' , table_schema = 'public' loop execute format ('copy %s.%s ''c:\data\%s_%s.csv'' (format csv)', r.table_schema, r.table_name, r.table_schema, r.table_name); end loop; end $$; select copy_my_tables();
Comments
Post a Comment