Insert data from a uploaded CSV file #493
Answered
by
lovasoa
Vipul-Cariappa
asked this question in
Q&A
-
I want to insert data into DB using an uploaded CSV file. How do I do it? My table structure: CREATE TABLE Student(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
RegNo CHAR(12) UNIQUE NOT NULL,
Name VARCHAR(50) NOT NULL,
Section VARCHAR(10) NOT NULL,
GNo INTEGER,
Interim INTEGER DEFAULT 0,
Final INTEGER DEFAULT 0,
Report INTEGER DEFAULT 0,
CONSTRAINT fk
FOREIGN KEY (Section) REFERENCES Section(Name),
FOREIGN KEY (GNo) REFERENCES Team(ID)
ON DELETE CASCADE
); The user would only update the I am able to get the contents of CSV file by doing this SET $csv_data = sqlpage.read_file_as_text(sqlpage.uploaded_file_path('csvFile'));
SELECT
'text' AS component,
$csv_data AS contents
WHERE
$csv_data IS NOT NULL;
SELECT
'form' AS component; But have no idea how to proceed.
SQLPages is an amazing project. Thanks. |
Beta Was this translation helpful? Give feedback.
Answered by
lovasoa
Jul 9, 2024
Replies: 1 comment 1 reply
-
Hello and welcome to SQLPage ! Did you take a look at Example 11: Bulk data insertion in https://sql.ophir.dev/documentation.sql?component=form#component ? |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Vipul-Cariappa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello and welcome to SQLPage !
Did you take a look at Example 11: Bulk data insertion in https://sql.ophir.dev/documentation.sql?component=form#component ?