psycopg: can't copy from csv to postgresql with python, no results -


I have simple postgresql db OID, the number of columns and their names are similar to the headers in the CSV file. I am trying to use the copy command:

  def db_copy_images (auto, file): try my_file = open (file): self.process_file ('images_original', my_file) Finally: DEF process_file pass (self, table, CSV_file): dbname = 'v' user = 'on' password = 'on' host = 'ip' port = 5432 SQL_STATEMENT = "copy% s from STDIN DELIMITER AS ' | ' CSV header "" print ("OK") Conn = psycopg2.connect (database = dbname, user = user, password = password, host = host, port = port) cursor = conn.cursor () for line in csv_file: Print (line) # cursor.copy_expert (sql = SQL_STATEMENT% table, file = csv_file) with cursor.copy_expert ("copy images_original delimiter from stdin as '|' CSV header '', file = csv_file) with cursor.execute ( "COMMIT,")  

I have found a list of rows in the form of output and then my process ends but There is no change in the database, and there are no errors, how can I debug it? Here is my --trace:

  manager_db.py (63): cursor.copy_expert ("STDOUT Copy images_original delimiters as in '|' CSV header ", file = csv_file) manager_db.py (66): cursor.execute (" COMMIT; ") manager_db.py (68): conn.commit manager_db.py ( 69): cursor.close manager_db.py (70): conn.close manager_db.py (36): pass --- modulename: trace, funcname: _unsettrace trace.py (80): sys.settrace (none)  

Here's my DB:

  

and fist lines in my test file:

  image id | file url | file format id | File formats | File width | File height | Il quality factor | file bit depth | file margin | file bg color | file size | scaling factor | delta 172317239 | http: //cps-static.r.com/2/Open/NBC/The%20Office/Steve%20Carell % 204 jpg | 0 || 2336 | 3504 ||||| 949,406 || INS 172,317,239 | http: //cps-static.r.com/2/Open/NBC/The%20Office/_derived_jpg_q90_0x200_m0/Steve%20Carell%204 Jpg | 1391886 | JPG | 133 | 200 | 90 | 24 | 24 | 6624 | 5.69 | INS 172317,239 | http: //cps-static.r.com/2/Open/NBC/The%20Office/_derived_jpg_q90_155x235_m0/ Steve% 20Carell% 204.jpg | 13 91887 | JPG | 155 | 232 | 90 | 24 | 0 | 24 | 8092 | 6.64 | INS  

Thanks for updating the question, a little unusual for the spaces in column names Is not impossible, though. I tried to enter my copy line directly from the psql command line and it worked. Then it jumped on me:

  in line for csv_file: print (line) csv_file.seek (0)  

When you print the data To start looking for the file file pointer (0), set it to reset

-g

this command should work, if you To find out the five-loop printing loop,

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -