PostgreSQL Database psql Command Line Query
Sometime psql command line query can be useful when it comes to Bash script processing. There are data stored in PostgreSQL database and I would like to write a bash script to massage the data into report. Example below show query to PostgreSQL database by using the psql command.
/usr/local/bin/psql -c "SELECT email_address FROM members WHERE active is TRUE;" -U someuser -t -A -o member-email-address.txt accounting
psql is connecting to accounting database, query from members table and out the result into a txt file name member-email-address.txt.
-t – Return result only, do not result with table name.
-A – By default, returned result will have white space, this is to remove the white space.
-o – Output the result into a file.
Related posts:
- Symfony, Unable to get sequence id with PostgreSQL Database When doing Symfony development, I usually build the database schema...
- How to Find Out Public IP Address via Command Line in Unix/Linux Machine If you have more than 100 servers in your network;...
- PostgreSQL Database signal 6 Error On Apple Mac After I have done PostgreSQL upgrade through MacPort, the database...
- installing postgresql 8.2 on Leopard with macports postgresql! one of my favorite high performance open source db,...
- Turn on DNS Query Log on Bind You are running a recursive DNS server and would like...
- Check DNS Record with Dig Command Check DNS Record with Dig Command How do you find...
- windows 2000 – command line (cmd) command auto completion By default, windows 2k server does not activate this function....
- Arrays in Bash Arrays is useful when it comes to data processing. Using...
- PgPool – PostgreSQL Connection Cache Playing PgPool on a heavy load database server is fun....
- PostgreSQL Performance Tuning Compilation Performance Tuning PostgreSQL by Frank Wiles PostgreSQL 8.0 Performance Checklist...
Tags: database, pgsql, postgresql, psql, query
August 21st, 2010 at 8:05 pm
Are you a japanese?
p/s
i am a japanese linux fun in KL
Regards