Skip to content

Instantly share code, notes, and snippets.

@Sdy603
Created October 15, 2024 20:30
Show Gist options
  • Save Sdy603/c4dadf96262bf74481ea847e255b28aa to your computer and use it in GitHub Desktop.
Save Sdy603/c4dadf96262bf74481ea847e255b28aa to your computer and use it in GitHub Desktop.
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