Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I used MSSQL where I could right click the result, copy with headers and paste it to Excel for a quick glance. Now with PostgreSQL I could only find 1.File > Export > CSV (long way) or 2.COPY (SELECT * FROM tbl) TO '/var/lib/postgres/myfile1.csv' (ERROR: must be superuser to COPY to or from a file)

Is there any easy way to take the data, put it in Excel for a quick glance?

Thank you!

share|improve this question
1  
You can't copy + paste from a backend server. Are you talking about the MS-SQL management console compared to PG-admin? Or are you using one of the other client applications? Oh - and I was assuming this was on Windows, but then you mentioned /var/lib... –  Richard Huxton Feb 7 '13 at 18:32
    
Creating client side exports (CSV, XLS, ...) is not really what the "database" does - be it PostgreSQL or SQL Server. It's always a client program which does the conversion. Which SQL client are you using? Are you looking for a different SQL tool which could do that? Or are you looking on how to do it with the tool you are using? –  a_horse_with_no_name Feb 7 '13 at 20:21
    
Sorry to leave out - I was using SQL Server Management Studio 2008 R2, and I am using PGAdmin III. –  user2051936 Feb 7 '13 at 21:25
    
Yes, '/var/lib/postgres/myfile1.csv' is misleading. I am using Windows so it should be c: etc etc. I just meant that one way is to include code instead of using GUI. One way, you mentioned, is to click the corner to select all, copy-paste, but that is leaving out the headers. –  user2051936 Feb 8 '13 at 22:15
    
I meant this one Copy (Select * From foo) To '/tmp/test.csv' With CSV; from stackoverflow.com/questions/1517635/… –  user2051936 Feb 8 '13 at 22:26

1 Answer 1

There's a lot of different ways to accomplish what you want here. The question is a bit confusing because you are talking about Excel, but then you table about '/var/lib/postgres/myfile1.csv', which makes me think you are now using some favor of Linux.

I'm using Ubuntu 12.04 with pgAdminIII 1.16.0. And I have Open Office installed with LibreOffice 3.5.4.2 as the Excel replacement.

I'm not sure why you want to take the information out of the grid in pgAdminIII, but assuming just wanting to take the data and move it over to a spreadsheet to play it for some reason, then about the easiest way to do it is run your query and click the upper left corner of the results (which just like a spreadsheet selects everything) and copy. Then, you should be able to open LibreOffice and paste in the information. It will bring up the same dialog as you would see when importing a CSV file.

Also, you should be able to start psql and then do a "COPY" command. If you get a permissions error, then try the suggested "\COPY" instead. Please see the PostgreSQL docs. Here is a link to a wiki page here.

If I'm missing what you are trying to do, please ask questions in the comments section, and I'll try to improve my answer accordingly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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