0

How I output select into a file?

I try

SELECT * FROM table \g filename

but I get “filename: Permission denied”

1 Answer 1

2

Either the file already exists and you have no write permission, or you have no write permission on your current working directory.

Try an absolute path:

SELECT * FROM atable \g /writable/directory/filename
Sign up to request clarification or add additional context in comments.

4 Comments

it is possible to change the name of the column when I execute a select, type the name of the column is customer_email and wanted by Email
Sure, use an alias: SELECT customer_email AS email.
` @classmethod def load_view_order_by_email(cls, email): with CursorFromConnectionPool() as cursor: cursor.execute('SELECT product_1, product_2, product_3, product_4, product_5, order_date FROM customer_order WHERE customer_email=%s \g /home/bruno/customer_order.txt', (email,))` is give a error because the \g ?
This works only with the psql client, it is not part of SQL.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.