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 9105883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:12:28+00:00 2026-06-17T02:12:28+00:00

I am currently outputting the results of an sql query to a CSV file

  • 0

I am currently outputting the results of an sql query to a CSV file with a header using the copy command in Postgresql. What I want to do is add a line break between the header and the start of the CSV data so that it is more readable.

Is there an easy way to do this by just altering my query? Thanks for your help!

  • 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-06-17T02:12:30+00:00Added an answer on June 17, 2026 at 2:12 am

    Actually, it is possible, although it is a bit of a hack:

    Rename the final column of the output using an AS clause in the query to add a newline character to the end of the column. You have to be sure to double-quote the column name in order to preserve the non-standard character, and you can’t use that column in the FORCE QUOTE clause of COPY.

    I was able to get it to work as you requested with this query:

    copy (select typname, typlen, typinput, typoutput as "typoutput^L" from pg_type limit 10) to stdout with csv header;
    

    The first three lines of output on my system look like this:

    typname,typlen,typinput,typoutput
    
    bool,1,boolin,boolout
    

    Please note that the “^L” in this output is my actually using the key combination in a Linux console in the PostgreSQL 9.2 psql client. Trying to use the string “^L” doesn’t work. Also, this doesn’t work either, although it gets you closer (note the line break):

    copy (select typname, typlen, typinput, typoutput as "typoutput
    " from pg_type limit 10) to stdout with csv header;
    

    This ends up with the first two lines looking like this:

    typname,typlen,typinput,"typoutput
    "
    

    Which isn’t quite correct.

    You’ll just need to tinker in your specific environment on how to get that newline character added but hopefully that’s enough info here to start.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running a JMeter test plan from command line and it's currently outputting something
I am outputting a textbox to the page using the Html helpers. I want
I have a Treeview control which is currently outputting the results in an HTML
I'm modifying a PHP script that I have and it is currently outputting a
Currently I am using HTML files for parts of my user interface. I display
currently, I`m implementing a map App with Mono4Droid and there I`m using a WebView
I am outputting a query but need to specify the first row of the
I am trying to write a Database Query to a file, But am just
I'm trying to stuff a variable into a SQL query to return a value
I'm using Linq to parse a simple XML file into a var (ienumerable), I'm

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.