How can I write a stored procedure that imports data from a CSV file and populates the table?
You can also use pgfutter, or, even better, pgcsv.
pgfutter is quite buggy, I'd recomment pgcsv.
Here's how to do it with pgcsv:
sudo pip install pgcsv pgcsv --db 'postgresql://localhost/postgres?user=postgres&password=...' my_table my_file.csv