我是靠谱客的博主 饱满黑夜,这篇文章主要介绍将csv文件导入python_使用Python将CSV数据导入postgreSQL,现在分享给大家,希望可以做个参考。

我正在尝试使用

Python将我拥有的CSV数据导入到postgreSQL中.它在我运行代码时显示(User)附近的错误.有人可以提供帮助.我是编程新手所以请原谅我的愚蠢.

import psycopg2

import csv

csv_data = csv.reader(file('SampleData2.csv'))

database = psycopg2.connect (database = "***", user="***", password="***", host="localhost", port="5432")

cursor = database.cursor()

delete = """Drop table if exists Real.SampleDataTwo"""

print (delete)

mydata = cursor.execute(delete)

cursor.execute("""Create Table Real.SampleDataTwo

(User varchar(55),

LastUpdate timestamp,

Week date,

Builder varchar(55),

Traffic integer

);""")

print "Table created successfully"

for row in csv_data:

cursor.execute("INSERT INTO Real.SampleDataTwo (User, LastUpdate, Week, Builder, Traffic)"

"VALUES (%s,%s,%s,%s,%s)",

row)

cursor.close()

database.commit()

database.close()

print "CSV data imported"

它显示的错误是:

Drop table if exists Real.SampleDataTwo

Traceback (most recent call last):

File "C:/Users/Programming/Data.py", line 20, in

);""")

ProgrammingError: syntax error at or near "User"

LINE 2: (User varchar(55),

^

最后

以上就是饱满黑夜最近收集整理的关于将csv文件导入python_使用Python将CSV数据导入postgreSQL的全部内容,更多相关将csv文件导入python_使用Python将CSV数据导入postgreSQL内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(111)

评论列表共有 0 条评论

立即
投稿
返回
顶部