Search code examples
javapostgresqlcopysqlbulkcopyout

How to copy a .out file to postgresql?


I have this file (warning: potentially unsafe file download site) that I need to insert into the database using Postgres and Java. Please download it and let me know how I can extract data from this file. I tried the copy command. For one, it did not let me use the header option. I have to, as you can see from the file, copy data from the 4th row onwards. Another thing is the delimiter. If you read the file in notepad++, you can see them as proper columns, but there is no delimiter as such. I have tried and faced these challenges. Please help me get a custom query. Or another approach that can achieve what I want to do. Thanks!

Edit: I have used a safer link to download the file. Hope it works.


Solution

  • So it sounds like you are doing fixed width files. COPY doesn't handle these so your best bet is to load up a spreadsheet, import the file (most can handle fixed width), and then export as csv. You can then use COPY.