A crash course in PostgreSQL, part 2

15.09.2011

What if you have a lot of data to insert? A fast way is to enter them in a plain text file, one data set per line in column order, with each field separated by a tab. Make sure there are no trailing newlines following your last line, or psql will give you a "missing data" error that references the empty lines. This example text file, freakbros.txt, contains two rows of data:

Fabulous Furry Freak Brothers 2 Rip Off Press 1973-04-19

Fabulous Furry Freak Brothers 3 Rip Off Press 1973-12-03

Populate your table with data from this file like this:

testdb=# \copy comics FROM '/home/carla/Documents/postgres/freakbros.txt'