Exporting data to SQL or CSV from a script

Is it possible to write a script that performs several SQL queries and then exports the results in SQL or CSV format to a file?

Or, to put it another way, is it possible to execute any non SQL commands inside a script? For example, to activate a feature available from the datagrip application?

0
2 comments

@gumbo

Do you want to invoke server config commands or just pgdump, mysqldump or something else?

Now we can execute SQL scripts and dump a result set to csv.

Could you describe your use case?

0

In datagrip I can execute an SQL query and then export the results in SQL INSERT, SQL UPDATES or CSV format. This is very good but it would even more useful if I can execute multiple SQL statements in a script and export the results.

Our product database has >1TB of data. When we are running tests we want to use a test database. Copying >1TB of data is not efficient and cloning the database would require another licence which is too costly. Therefore we use a free development test database. The test database also has limited specifications so we cannot populate it with too much data anyway.

When we are running tests we need we only need data related to a specific project for running a test. We would like to be able to write a script that extracts a subset of data for loading into a test database. If I could write a script with multiple SQL statements for extracting test data from multiple tables and then export all the results in SQL INSERT format to a file this would make my job easier.

It appears to me the datagrip has much of the functionality already built in that I need. If datagrip could execute multiple SQL statements and export the results into a single file this would be incredibly useful.

 

0

Please sign in to leave a comment.