How can I write a stored procedure that imports data from a CSV file and populates the table?
IMHO, the most convenient way is to follow "Import CSV data into postgresql, the comfortable way ;-)", using csvsql from csvkit, which is a python package installable via pip.