You can try writing a script in python which might help you achieve your desired task. You can use psycopg2
library to connect with the PostgresDB and further use the script below:
import psycopg2
import os
def load_csv_as_label(dbname, user, password, host, port, graph_name, csv_path):
# Extract filename (without extension) as label from the csv_path
label_name = os.path.splitext(os.path.basename(csv_path))[0]
try:
# Establish a connection to the PostgreSQL database
conn = psycopg2.connect(
dbname=dbname,
user=user,
password=password,
host=host,
port=port,
)
# Create a new database session and return a new instance of the connection class
cur = conn.cursor()
# Create a new vertex label with the extracted filename
cur.execute(f"SELECT create_vlabel('{graph_name}', '{label_name}')")
# Load data from the csv file into the new vertex label
cur.execute(f"SELECT load_labels_from_file('{graph_name}', '{label_name}', '{csv_path}')")
# Commit the transaction
conn.commit()
print(f"Data loaded successfully from {csv_path} to {label_name} label")
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
you can call this function using:
load_csv_as_label('my_database', 'my_user', 'my_password', 'localhost', 5432, 'agload_test_graph', '/home/kamleshk/age_installation/age/regress/age_load/data/countries.csv')