On Sun, Jan 16, 2011 at 11:15 AM, Reed Loefgren <[email protected]> wrote: > IF you have some degree of access to the DB itself you might be able to do > this using psql: > > db> \? For all kinds of information. > db> \H Set output to html. It's an (aligned/html) toggle. > db> \cd /tmp Changes location to that directory. > db> \o 'file.extension' Sets the output file's name and type. > db> select * from charts limit 3; Submits query and writes output to a > file called /tmp/file.extension. > dg> \q Quits to a prompt. I believe quitting will also reset all toggles to > their defaults. > > You can script this somewhat like a DOS batch file or a shell script. You'll > have to do your homework: > psql -U someuser -d somedb < /tmp/my_script.txt > > Of course, if your account and/or db have not been set up wisely you might > unknowingly wield a great deal of power; think a bit before hitting 'Enter'. > Or wait for somebody to perl-ify such actions within the app.
The following one liner can also achieve this in 'psql' COPY (SELECT id, partnumber, description FROM parts ORDER BY partnumber) TO '/tmp/parts.csv' CSV HEADER; Regards Armaghan _______________________________________________ SQL-Ledger mailing list [email protected] http://lists.ledger123.com/mailman/listinfo/sql-ledger
