-
Notifications
You must be signed in to change notification settings - Fork 17
/
sqllite
68 lines (51 loc) · 1.86 KB
/
sqllite
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
SQLITE_DB_PATH=$1
PG_DB_NAME=$2
PG_USER_NAME=$3
SQLITE_DUMP_FILE="sqlite_data.sql"
sqlite3 $SQLITE_DB_PATH .dump > $SQLITE_DUMP_FILE
# PRAGMAs are specific to SQLite3.
sed -i '/PRAGMA/d' $SQLITE_DUMP_FILE
# Convert sequences.
sed -i '/sqlite_sequence/d ; s/integer PRIMARY KEY AUTOINCREMENT/serial PRIMARY KEY/ig' $SQLITE_DUMP_FILE
# Convert column types.
sed -i 's/datetime/timestamp/g ; s/integer[(][^)]*[)]/integer/g ; s/text[(]\([^)]*\)[)]/varchar(\1)/g' $SQLITE_DUMP_FILE
createdb -U $PG_USER_NAME $PG_DB_NAME
psql $PG_DB_NAME $PG_USER_NAME < $SQLITE_DUMP_FILE
# Update Postgres sequences.
psql $PG_DB_NAME $PG_USER_NAME -c "\ds" | grep sequence | cut -d'|' -f2 | tr -d '[:blank:]' |
while read sequence_name; do
table_name=${sequence_name%_id_seq}
psql $PG_DB_NAME $PG_USER_NAME -c "select setval('$sequence_name', (select max(id) from $table_name))"
done
====
sed -i '/TINYINT/INTEGER/g' $SQLITE_DUMP_FILE
sed -i '/sqlite_sequence/d ; s/integer NOT NULL PRIMARY KEY AUTOINCREMENT/serial NOT NULL PRIMARY KEY/ig' $SQLITE_DUMP_FILE
#sqllite.sh
-------
DRUG_TARGETS_ORG
"name","type"
"target_drugs","TEXT"
"uniprot_id","TEXT"
"Organism","TEXT"
ENSB_UNIPROT
"name","type"
"ensemble_id","TEXT"
"uniprot_id","TEXT"
========
CREATE TABLE DRUG_TARGETS_ORG(
ID INT PRIMARY KEY NOT NULL,
TARGET_DRUGS TEXT NOT NULL,
UNIPROT_ID TEXT NOT NULL,
ORGANISM TEXT NOT NULL
);
CREATE TABLE / PRIMARY KEY will create implicit index "drug_targets_org_pkey" for table "drug_targets_org"
CREATE TABLE
CREATE TABLE ENSB_UNIPROT(
ID INT PRIMARY KEY NOT NULL,
ENSEMBLE_ID TEXT NOT NULL,
UNIPROT_ID TEXT NOT NULL
);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "ensb_uniprot_pkey" for table "ensb_uniprot"
CREATE TABLE
=====
COPY wheat FROM 'wheat_crop_data.csv' DELIMITER ';' CSV HEADER