How to use Copy Command in a loop?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kallem
    New Member
    • Jan 2011
    • 6

    How to use Copy Command in a loop?

    hi,

    [COPY worktrainees_hi story FROM E'C:\\bcp\\work trainees_histor y.txt' USING DELIMITERS ',' CSV]

    the above command is working fine but i have more than 100 tables and related text files i wanted to run in a loop but
    when i use a parameter for table name it is giving error so can any one give me example for this
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    Write a script to do that.

    Comment

    • kallem
      New Member
      • Jan 2011
      • 6

      #3
      can you give sample script i dont know how to do that

      Comment

      • rski
        Recognized Expert Contributor
        • Dec 2006
        • 700

        #4
        In linux
        Code:
        for i in <list of tables>;
        do
        psql <database and user parameters> -c "COPY ${i} FROM E'C:\\bcp\\${i}.txt' USING DELIMITERS ',' CSV"
        Probably under windows you sould be able to do that in similar way, but I'm not a windows expert.

        Comment

        Working...