473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

SELECT to an external file

Hi,

How can i draw the results of a SELECT in to a file in the filesystem ?

Warm Regards,
Mário Gamito

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #1
5 1826
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,

On Tue, 24 Aug 2004, [ISO-8859-1] Mário Gamito wrote:
How can i draw the results of a SELECT in to a file in the filesystem ?


Use \o:

test=# \o testfile
test=# SELECT * from mytable;
test=#

All the output is redirected to testfile.

Regards,
- --
Devrim GUNDUZ
devrim~gunduz.org devrim.gunduz~linux.org.tr
http://www.tdmsoft.com
http://www.gunduz.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFBK3cJtl86P3SPfQ4RAqXlAJ4rpEmebsqRM5f6eWLX6D KMdlFZ8QCgvzHk
bSMZ2kr9s9brM6U6Bn27jJs=
=CREY
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #2
On Tue, 2004-08-24 at 18:08, Mário Gamito wrote:
Hi,

How can i draw the results of a SELECT in to a file in the filesystem ?


Using psql:

1. \o /path/to/file
SELECT ... ;
\o

2. psql -d my_database -c "SELECT ... " >/path/to/file

--
Oliver Elphick ol**@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"I saw in the night visions, and, behold, one like the
Son of man came with the clouds of heaven, and came to
the Ancient of days, and they brought him near before
him. And there was given him dominion, and glory, and
a kingdom, that all people, nations, and languages,
should serve him; his dominion is an everlasting
dominion, which shall not pass away, and his kingdom
that which shall not be destroyed."
Daniel 7:13,14
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #3
Hi,

First of all, thank you for your answers.

Look at this file output:

url_negado
------------------------------------------------------------------------------------------------------
www.startux.org
www.hotmail.com
www.blabla.com
(3 rows)
Is there a way to postgres not print the 1st, 2nd and last line ?
I need a list just with URLs.

Thank you in advance.

Warm Regards,
Mário Gamito

Oliver Elphick wrote:
On Tue, 2004-08-24 at 18:08, Mário Gamito wrote:
Hi,

How can i draw the results of a SELECT in to a file in the filesystem ?

Using psql:

1. \o /path/to/file
SELECT ... ;
\o

2. psql -d my_database -c "SELECT ... " >/path/to/file


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #4
psql -c "select * from table" dbname >filename.txt

Mário Gamito wrote:
Hi,

How can i draw the results of a SELECT in to a file in the filesystem ?

Warm Regards,
Mário Gamito

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #5
use the psql -t option

Jeff

Mário Gamito wrote:
Hi,

First of all, thank you for your answers.

Look at this file output:

url_negado
------------------------------------------------------------------------------------------------------

www.startux.org
www.hotmail.com
www.blabla.com
(3 rows)
Is there a way to postgres not print the 1st, 2nd and last line ?
I need a list just with URLs.

Thank you in advance.

Warm Regards,
Mário Gamito

Oliver Elphick wrote:
On Tue, 2004-08-24 at 18:08, Mário Gamito wrote:
Hi,

How can i draw the results of a SELECT in to a file in the filesystem ?


Using psql:

1. \o /path/to/file
SELECT ... ;
\o

2. psql -d my_database -c "SELECT ... " >/path/to/file


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ActiveUp | last post by:
http://www.activeup.com/products/components/activecalendar Active Calendar is an ASP.NET server control that allows users to select a date and/or time quickly using a professional looking date...
1
by: Aravind | last post by:
we have two files: 1. rc4.c (defines one function "create_pin()") 2. MyImpl.c(calling the function "create_pin()"),This implements JNI method. 1.When I am trying to create .dll file with one...
4
by: Peter Ammon | last post by:
I would like to share a variable between two functions defined in two separate source files; no other functions will need the global variable so I'd prefer to not give it file scope. Thus, I want...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
19
by: natG | last post by:
On a warehouse app, our Java clients constantly load/insert rows into the db. I would like to throttle these inserts (1.5 million rows per hr) from the Java app, based on current 'busy state' of...
1
by: Brian Kendig | last post by:
I've got some questions about using an external javascript file, included via '<script type="text/javascript" src="mycode.js" ></ script>': (1) If I define a function "myFunction()" in the...
0
debasisdas
by: debasisdas | last post by:
This thread contains some useful tips for using External tables. USING EXTERNAL TABLE ======================= 1.THE TABLE POINTS TO EXTERNAL FILE. IF DATA IS ALTERED IN THE EXTERNAL FILE,DATA...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.