Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import psycopg2
  2. import csv
  3. import string
  4.  
  5. # Connect to an existing database
  6. conn = psycopg2.connect("dbname=postgres user=postgres password=xxxx")
  7.  
  8. cur = conn.cursor()
  9.  
  10. # create a table
  11. cur.execute("CREATE TABLE ADDRESS_SITE (ADDRESS_DETAIL_PID varchar(15) PRIMARY KEY, DATE_CREATED Date,
  12. # DATE_RETIRED Date, ADDRESS_TYPE varchar(8), ADDRESS_SITE_NAME varchar(45));")
  13.  
  14. file = open("/Users/jubertroldan/GNAF/AUG17_GNAF_PipeSeparatedValue_20170821153434/G-NAF/G-NAF AUGUST 2017/Standard/NSW_ADDRESS_SITE_psv.psv","r")
  15.  
  16. with file as f:
  17. next(f)
  18. for line in f:
  19. print(f.readline().count('|'))
  20. print(f.readline())
  21. cur.copy_from(f, 'ADDRESS_SITE', sep="|",null = '')
  22. conn.commit()
  23. file.close()
  24.  
  25. Traceback (most recent call last):
  26. File "GNAF_ADDRESS_SITE.py", line 43, in <module>
  27. cur.copy_from(f, 'ADDRESS_SITE', sep="|",null = '')
  28. psycopg2.DataError: extra data after last expected column
  29. CONTEXT: COPY address_site, line 1379807: "713005737|2015-04-28||UN|EASEMENT FOR OVERHANG 0.7 WIDE
  30. 701367558|2004-02-23||UN|"
  31.  
  32. 01367554|2004-02-23||UN|
  33. 701367555|2004-02-23||UN|
  34. 701367556|2004-02-23||UN|
  35. 713005737|2015-04-28||UN|EASEMENT FOR OVERHANG 0.7 WIDE
  36. 701367558|2004-02-23||UN|
  37. 701367559|2004-02-23||UN|
  38. 701367560|2004-02-23||UN|
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement