dynamic postgres inside shell script not working PG_CMD="psql -d portal -U portal -c "
PG_CMD_TP="psql -d portal -U portal -t -P format=unaligned -c "
abc()
{
 $PG_CMD " 
        DO \$$

           BEGIN
                   select * from customer;
          END; 
        \$$";
}
*******MAIN***
abc


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:


You cannot return data from a DO command.
You cannot SELECT without target in plpgsql code. That's what the error message tells you.
You don't need either for a simple SELECT statement. Just run the statement itself:




abc()
{
 $PG_CMD 'select * from customer'
}