PROBLEM:
I have a CSV file with 16,382 columns with data that looks like this:
+-------------+-----------+------+-------+------+------+------+-----+-------+-----+
| PATIENT_ID | DIAGNOSIS | 1 | 2 | 3 | 9 | 10 | 13 | 14 | ... |
+-------------+-----------+------+-------+------+------+------+-----+-------+-----+
| X764_130520 | 0 | 0.35 | 9.68 | 0.11 | 0.04 | 0.03 | 0 | 32.54 | |
| X800_130701 | 0 | 2.24 | 32.04 | 0.13 | 0.34 | 0.04 | 0 | 39.47 | ... |
| X164_120423 | 6 | 3.12 | 24.08 | 0.04 | 0.1 | 0.08 | 0 | 73.47 | ... |
| X218_120425 | 6 | 2.48 | 20.62 | 0 | 0.22 | 0 | 0 | 59.06 | ... |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | |
| X824_130725 | 1 | 0.76 | 44.77 | 0.1 | 0.28 | 0.13 | 0 | 45.35 | |
+-------------+-----------+------+-------+------+------+------+-----+-------+-----+
RAW FORMAT:
PATIENT_ID,DIAGNOSIS,1,2,3,9,10,13,14,15,16,18,19,20,21,22,23,24,25,...
X764_130520,0,0.35,9.68,0.11,0.04,0.03,0,32.54,0.13,49.73,33.34,0.77,..
X800_130701,0,2.24,32.04,0.13,0.34,0.04,0,39.47,0.51,44.92,...
X218_120425,6,2.48,20.62,0,0.22,0,0,59.06,0.11,86.48,62.63,1.09,110.83,...
X266_120430,6,2.66,19.95,0.05,0.13,0.1,0,39.72,0.32,41.78,40.78,1.03,...
X276_120430,6,2.45,14.64,0,0.06,0.1,0,60.77,0.34,88.92,59.66,...
X411_120503,6,3.33,28.23,0,0.19,0.04,0,54.92,0.52,64.29,53.62,0.7,...
X448_120507,6,2.48,22.98,0,0.08,0,0,46.58,0.25,67.85,57.76,...
X517_120515,6,3.5,30.19,0.07,0.07,0.03,0.02,51.38,0.25,67.89,56.2,1.07,...
Except for the first two columns, everything else afterward are 16,380 columns of floating points. The heading for these floating points are integer IDs of human genes and are not contiguous natural numbers.
WHAT I WANT:
I am using PostgreSQL 9.5.6 on 64-bit Linux based on Ubuntu 16.04.4
I want to put the 16,380 numbers into a REAL array of size 16,380 in PostgreSQL, but I am lost as to how to do this.
I want the table in PostgreSQL to look like this:
+------------+-----------+---------------+
| patient_id | diagnosis | gene_id |
+------------+-----------+---------------+
| ... | ... | {...,...,...} |
| ... | ... | {...,...,...} |
| ... | ... | {...,...,...} |
+------------+-----------+---------------+
I created the table above with this code:
CREATE TABLE rosmap_rnaseq_entrez (
patient_id VARCHAR(20),
diagnosis INTEGER,
gene_id REAL[16380]
);
I just need to find a proper SQL command to import the CSV file into the table above.