-1

I'd like to know if there's a way do so something like this :

lab-2:/tmp# echo  46692,46694,46696,46704,46708,46709,46713,46730,46736,46574 > deletelist.txt
lab-2:/tmp# cat deletelist.txt
46692,46694,46696,46704,46708,46709,46713,46730,46736,46574

And then I'd like to pass the list into a delete command via psql. So far, this is what I tried but as you can see it's failing:

   lab-2:/tmp# psql -U test testdb -c "Delete from widgets where id in (" <deletelist.txt ")"
    psql: warning: extra command-line argument ")" ignored
    ERROR:  syntax error at end of input
    LINE 1: Delete from mist_cdr where id in (
                                          ^

EDIT 1

Attempting the suggested answer gives the following results:

lab-2:/tmp# psql -U test testdb -c "delete from widgets where id in ( $(</tmp/deletelist.txt ))"
ERROR:  syntax error at or near ")"
LINE 1: delete from widgets where id in ( )
                                           ^
lab-2:/tmp#

Also tried the same command without the path, like so:

lab-2:/tmp# psql -U test testdb -c "delete from widgets where id in ( $(<deletelist.txt ))"

but same results

  • 1
    just wondering why i got dinged for this question? poorly worded? bad question? I'm afraid i'm no good with bash and didn't know what keywords to google – dot Mar 1 '18 at 20:39
1

Try to use within command substitution.

psql -U test testdb -c "Delete from widgets where id in ( $(<deletelist.txt) )"
  • that doesn't seem to work. will update my question with results – dot Mar 1 '18 at 21:35
  • Would you add a semicolon at the end of the statement and check if that works? – αғsнιη Mar 2 '18 at 0:02

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.