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:

  1. Symfony, Unable to get sequence id with PostgreSQL Database When doing Symfony development, I usually build the database schema...
  2. How to Find Out Public IP Address via Command Line in Unix/Linux Machine If you have more than 100 servers in your network;...
  3. PostgreSQL Database signal 6 Error On Apple Mac After I have done PostgreSQL upgrade through MacPort, the database...
  4. installing postgresql 8.2 on Leopard with macports postgresql! one of my favorite high performance open source db,...
  5. Turn on DNS Query Log on Bind You are running a recursive DNS server and would like...
  6. Check DNS Record with Dig Command Check DNS Record with Dig Command How do you find...
  7. windows 2000 – command line (cmd) command auto completion By default, windows 2k server does not activate this function....
  8. Arrays in Bash Arrays is useful when it comes to data processing. Using...
  9. PgPool – PostgreSQL Connection Cache Playing PgPool on a heavy load database server is fun....
  10. PostgreSQL Performance Tuning Compilation Performance Tuning PostgreSQL by Frank Wiles PostgreSQL 8.0 Performance Checklist...

Tags: , , , ,

One Response to “PostgreSQL Database psql Command Line Query”

  1. kitamura Says:

    Are you a japanese?

    p/s
    i am a japanese linux fun in KL

    Regards

Leave a Reply