Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mimic-iii/buildmimic/duckdb/import_duckdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ make_table_name () {
# load data into database
find "$MIMIC_DIR" -type f -regex '.*\.csv\(.gz\)*' | while IFS= read -r FILE; do
make_table_name "$FILE"
# escape single quotes for SQL string literal
FILE_SQL=${FILE//\'/\'\'}
echo "Loading $FILE .. \c"
try duckdb "$OUTFILE" <<-EOSQL
COPY $TABLE_NAME FROM '$FILE' (HEADER, DELIM ',', QUOTE '"', ESCAPE '"');
COPY $TABLE_NAME FROM '$FILE_SQL' (HEADER, DELIM ',', QUOTE '"', ESCAPE '"');
EOSQL
echo "done!"
done && echo "Successfully finished loading data into $OUTFILE."
4 changes: 3 additions & 1 deletion mimic-iv-ed/buildmimic/duckdb/import_duckdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ make_table_name () {
# load data into database
find "$MIMIC_DIR" -type f -name '*.csv???' | sort | while IFS= read -r FILE; do
make_table_name "$FILE"
# escape single quotes for SQL string literal
FILE_SQL=${FILE//\'/\'\'}

# skip directories which we do not expect in mimic-iv-ed
# avoids syntax errors if mimic-iv in the same dir
Expand All @@ -104,7 +106,7 @@ find "$MIMIC_DIR" -type f -name '*.csv???' | sort | while IFS= read -r FILE; do
esac
echo "Loading $FILE .. "
try duckdb "$OUTFILE" <<-EOSQL
COPY $TABLE_NAME FROM '$FILE' (HEADER, DELIM ',', QUOTE '"', ESCAPE '"');
COPY $TABLE_NAME FROM '$FILE_SQL' (HEADER, DELIM ',', QUOTE '"', ESCAPE '"');
EOSQL
echo "done!"
done && echo "Successfully finished loading data into $OUTFILE."
4 changes: 3 additions & 1 deletion mimic-iv-note/buildmimic/duckdb/import_duckdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ make_table_name () {
# load data into database
find "$MIMIC_DIR" -type f -name '*.csv???' | sort | while IFS= read -r FILE; do
make_table_name "$FILE"
# escape single quotes for SQL string literal
FILE_SQL=${FILE//\'/\'\'}

# skip directories which we do not expect in mimic-iv-note
# avoids syntax errors if mimic-iv in the same dir
Expand All @@ -107,7 +109,7 @@ find "$MIMIC_DIR" -type f -name '*.csv???' | sort | while IFS= read -r FILE; do
esac
echo "Loading $FILE .."
OUTPUT=$(duckdb "$OUTFILE" 2>&1 <<-EOSQL
COPY $TABLE_NAME FROM '$FILE' (HEADER, DELIM ',', QUOTE '"', ESCAPE '"');
COPY $TABLE_NAME FROM '$FILE_SQL' (HEADER, DELIM ',', QUOTE '"', ESCAPE '"');
EOSQL
)
# If the table is missing in the DB, we emit a warning and continue.
Expand Down
4 changes: 3 additions & 1 deletion mimic-iv/buildmimic/duckdb/import_duckdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ make_table_name () {
# load data into database
find "$MIMIC_DIR" -type f -name '*.csv???' | sort | while IFS= read -r FILE; do
make_table_name "$FILE"
# escape single quotes for SQL string literal
FILE_SQL=${FILE//\'/\'\'}

# skip directories which we do not expect in mimic-iv
# avoids syntax errors if mimic-iv-ed in the same dir
Expand All @@ -112,7 +114,7 @@ find "$MIMIC_DIR" -type f -name '*.csv???' | sort | while IFS= read -r FILE; do
esac
echo "Loading $FILE .. \c"
OUTPUT=$(duckdb "$OUTFILE" 2>&1 <<-EOSQL
COPY $TABLE_NAME FROM '$FILE' (HEADER, DELIM ',', QUOTE '"', ESCAPE '"');
COPY $TABLE_NAME FROM '$FILE_SQL' (HEADER, DELIM ',', QUOTE '"', ESCAPE '"');
EOSQL
)
# If the table is missing in the DB, we emit a warning and continue.
Expand Down
Loading