This are the first three lines of my text file:
Dist Mv CL Typ LTef logg Age Mass B-V U-B V-I V-K V [Fe/H] l b Av Mbol
0.033 14.40 5 7.90 3.481 5.10 1 0.15 1.723 1.512 3.153 5.850 17.008 0.13 0.50000 0.50000 0.014 12.616
0.033 7.40 5 6.50 3.637 4.62 7 0.71 1.178 0.984 1.302 2.835 10.047 -0.56 0.50000 0.50000 0.014 6.125
0.052 11.70 5 7.40 3.529 4.94 2 0.31 1.541 1.167 2.394 4.565 15.393 -0.10 0.50000 0.50000 0.028 10.075
Assuming I have the right columns, how do I import this?
Bonus: is it possible/are there tools to create the schema from these kinds of files automatically?
At lowest level you could just use
COPYcommand (or\copyinpsqlif you don’t have access to superuser account, whichCOPYrequires to load data from file). Unfortunately you have to create table structure at first (there is no built-in guess-by-header feature), but it looks straightforward to write one.Choose whaterer suitable datatype you need e.g.
realfor single precision floating-point (IEEE 754),double precisionornumericif you need arbitrary precision numbers:Another thing is that your file contains multiple spaces between values, so it’s better to transform it into single-tab-delimited entries (there are plenty of tools to do this):
Finally you can import your file straight into Postgres database, for example: