0

I am currently trying to set up a query that will eventually be a Stored procedure and probably a job that runs, I need the query to automatically output the result into a file. I have found 50 different ways to do this manually and 0 ways to do this in the query, any ideas on how I could spit the following query into a file.

SELECT [FULL_NAME],[ADDRESS],[PHONE] FROM CUSTOMER

Edit: I use Microsoft SQL Server

1 Answer 1

0

If you use postgres you can write a BASH script that will connect to the database and dump the result of the query directly from the psql:

\copy (SELECT [FULL_NAME],[ADDRESS],[PHONE] FROM CUSTOMER) to '/file.txt';

Or a simple python script that connects to the database, queries it and dumps what he received to the file. You can find tutorial on how to do it all over the internet. For postgres database there is package psycopg2. You can read more here: https://www.psycopg.org/docs/

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.