PG_CMD="psql -d portal -U portal -c "
PG_CMD_TP="psql -d portal -U portal -t -P format=unaligned -c "
 $PG_CMD " 
        DO \$$

                   select * from customer;

I want to print result of query on command line as well as I want to send it to excel file.

ERROR:  query has no destination for result data

Three misunderstandings:

  1. You cannot return data from a DO command.

  2. You cannot SELECT without target in plpgsql code. That's what the error message tells you.

  3. You don't need either for a simple SELECT statement. Just run the statement itself:

 $PG_CMD 'select * from customer'
| improve this answer | |
  • thanks Erwin just one more question I need to use variable value inside copy function while writing in .csv format – user3526905 Feb 25 '15 at 7:10
  • @user3526905: That's seems like an unrelated question. Please start a new question, comments are not the place. Or consider related question on SO like here or here. – Erwin Brandstetter Feb 25 '15 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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