Issue
I'm creating a script that blends a load of tsv files with the aim of then importing the data into my sqlite3 table. However, I have noticed that one of my files doesn't seem to get imported with my script like all the others. It also doesn't appear to import when I run it manually.
As the data is able to get into the temp table without issue, I thought the issue may lie with the date column, but even with amending it in the data to be in Y-M-D format, for some reason it still doesn't import.
Can someone confirm what seems to be wrong with the sample data as all other tsv files appear to import without issue?
sample.tsv
company1 account1 platform1 05/05/2020 28823 client1 191361
company2 account2 platform2 05/05/2020 47188 cleint2 16597
company3 account3 platform3 05/06/2020 28823 client1 191903
company4 account4 platform4 05/06/2020 47188 cleint2 15407
company5 account5 platform5 05/07/2020 28823 client1 196450
company6 account6 platform6 05/07/2020 47188 cleint2 14678
company7 account7 platform7 05/08/2020 28823 client1 191809
company8 account8 platform8 05/08/2020 47188 cleint2 14489
company9 account9 platform9 05/09/2020 28823 client1 195405
script.sh
#!/bin/bash
set -eu
cd final/client/
for f in $(find -mindepth 1 -maxdepth 1 -type f -name "*.tsv" -printf "%f\n"); do
sqlite3 -batch ~/SQL/.databases/database.db <<EOF
CREATE TABLE IF NOT EXISTS companydata_client(
Company TEXT NOT NULL,
Account TEXT NOT NULL,
Platform TEXT NOT NULL,
Impression_Date_Delivered DATE NOT NULL,
Client_ID TEXT NOT NULL,
Client TEXT NOT NULL,
Impressions INTEGER,
UNIQUE(Company,Account,Platform,Impression_Date_Delivered,Client_ID, Client,Impressions)
);
CREATE TEMPORARY TABLE wand(
Company TEXT NOT NULL,
Account TEXT NOT NULL,
Platform TEXT NOT NULL,
Impression_Date_Delivered DATE NOT NULL,
Client_ID TEXT NOT NULL,
Client TEXT NOT NULL,
Impressions INTEGER
);
.mode tabs
.separator \t
.import $f wand
INSERT OR IGNORE INTO companydata_client (Company,Account,Platform,Impression_Date_Delivered,Client_ID,Client,Impressions)
SELECT
CAST (Company AS TEXT),
CAST (Account AS TEXT),
CAST (Platform AS TEXT),
strftime('%d-%m-%Y',Impression_Date_Delivered),
CAST (Client_ID AS Text),
CAST (Client AS TEXT),
CAST (Impressions AS Integer)
FROM wand;
EOF
done
cd ../../