【发布时间】:2017-10-19 17:50:25
【问题描述】:
我有一个 CSV 文件,其中包含 2 列:数据库的列名及其数据类型。我希望编写一个 python 代码,使用每个列名及其数据类型创建 SQL 查询。之前我使用的代码将每种数据类型泛化为 varchar。
大约有100列。
这里需要一些想法..
# for every column in the list of columns
for i in range(number_of_columns):
# if it is any column other than the last column
if i != number_of_columns-1:
# comma after every column
CREATE_TABLE_SQL_QUERY += "%s VARCHAR(50)," %(header_list[i])
# if it is the last column
else:
# no comma after last column
CREATE_TABLE_SQL_QUERY += "%s VARCHAR(50))" %(header_list[i])
# prints the SQL query the needs to be executed for this file's table
print(CREATE_TABLE_SQL_QUERY)
【问题讨论】:
-
可以告诉我们您面临什么问题,您还需要显示 CSV 的内容以了解您实际尝试过的内容