Advertisement
chrissharp123

Untitled

Jul 12th, 2019
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.64 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #This script is to delete any purchase orders that are pending, named delete, and have no line items or direct charges.
  4.  
  5. #set up the environment
  6. PSQL="/usr/bin/psql"
  7. DB_USER="evergreen"
  8. DB_HOST="db01"
  9. read -r -d '' SQL << 'EOF'
  10. DELETE FROM acq.purchase_order po
  11.         LEFT JOIN acq.lineitem li ON (li.purchase_order = po.id)
  12.         LEFT JOIN acq.po_item poi on (poi.purchase_order = po.id)
  13. WHERE   acq.lineitem.id IS NULL
  14.         AND po.state = 'pending'
  15.         AND poi.id IS NULL
  16.         AND po.name ILIKE '%delete%'
  17. EOF
  18.  
  19. #do the thing
  20.  
  21. #$PSQL -U $DB_USER -h $DB_HOST -1 -c "$SQL"
  22. echo $SQL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement