Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6794971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:17:12+00:00 2026-05-26T18:17:12+00:00

I need to export the resulting data from a query in PostgreSQL to Excel/CSV.

  • 0

I need to export the resulting data from a query in PostgreSQL to Excel/CSV.
I use PostgreSQL 8.2.11.

SQL error:

ERROR:  relative path not allowed for COPY to file
In statement:

COPY (select distinct(m_price) from m_product)TO '"c:\auto_new.txt"';
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:17:13+00:00Added an answer on May 26, 2026 at 6:17 pm

    Example with Unix-style file name:

    COPY (SELECT * FROM tbl) TO '/var/lib/postgres/myfile1.csv' format csv;
    

    Read the manual about COPY (link to version 8.2).
    You have to use an absolute path for the target file. Be sure to double quote file names with spaces. Example for MS Windows:

    COPY (SELECT * FROM tbl)
    TO E'"C:\\Documents and Settings\\Tech\Desktop\\myfile1.csv"' format csv;
    

    In PostgreSQL 8.2, with standard_conforming_strings = off per default, you need to double backslashes, because \ is a special character and interpreted by PostgreSQL. Works in any version. It’s all in the fine manual:

    filename

     The absolute path name of the input or output file. Windows users might need to use an E'' string and double backslashes used as path separators.

    Or the modern syntax with standard_conforming_strings = on (default since Postgres 9.1):

    COPY tbl  -- short for (SELECT * FROM tbl)
    TO '"C:\Documents and Settings\Tech\Desktop\myfile1.csv"' (format csv);
    

    Or you can also use forward slashes for filenames under Windows.

    An alternative is to use the meta-command \copy of the default terminal client psql.

    You can also use a GUI like pgadmin and copy / paste from the result grid to Excel for small queries.

    Closely related answer:

    • Copy results from a PostgreSQL view in one DB to a table in another

    Similar solution for MySQL:

    • Exporting MYSQL data into Excel/CSV via php
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to export some data from PostgreSQL to Excel (quick customer wish), and
I need to export the data from 36 SQL tables containing 24GB of data
I need to export data from php to Excel, and be able to format
I need to export multiple data tables to Excel on the clients machine, each
I need to export the results of a query to a csv file and
I need to export some data to excel in my forms aplication, so i
I need to export my EditorGridPanel grid data to excel without sending any data
I need to export the Users List from excel to my asp.net mvc(C#) application.
I'm running SQL Server 2000 and I need to export the SQL Statement from
I have a query that selects 3 columns from a SQL table, I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.