Created
October 15, 2024 20:30
-
-
Save Sdy603/c4dadf96262bf74481ea847e255b28aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
# Function to generate insert statements from CSV data and write them to a SQL file | |
def generate_insert_statements(csv_file_path, output_sql_file): | |
insert_statements = [] | |
with open(csv_file_path, 'r') as file: | |
reader = csv.DictReader(file) | |
with open(output_sql_file, 'w') as sql_file: | |
for row in reader: | |
namespace = row['namespace'] | |
key = row['key'] | |
accountable_party_id = row['accountablePartyId'] | |
count = row['count()'] | |
# Construct the insert statement | |
insert_statement = f"INSERT INTO ownership (namespace, key, accountable_party_id, count) VALUES ('{namespace}', '{key}', '{accountable_party_id}', {count});\n" | |
# Write the insert statement to the file | |
sql_file.write(insert_statement) | |
print(f"Insert statements written to {output_sql_file}") | |
# File path to the CSV file | |
csv_file_path = "ownership.csv" | |
# Output SQL file path | |
output_sql_file = "IndeedOwnership.sql" | |
# Generate insert statements from the CSV data and write to SQL file | |
generate_insert_statements(csv_file_path, output_sql_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment