You'll need to do one of these 3 ideas:
- use an ETL tool to filter the data during insert;
COPY
into aTEMPORARY
orUNLOGGED
table then do anINSERT INTO real_table SELECT ...
that transforms the data with a suitablesubstring(...)
call; or- Write a simple Perl/Python/whatever script that reads the csv, transforms it as desired, and inserts the results into PostgreSQL. I'd use Python with the
csv
module and psycopg2'scopy_from
.
Such an insert into ... select
might look like:
INSERT INTO real_table(col1, col2, zip)
SELECT
col1,
col2,
substring(zip from 1 for 5)
FROM temp_table;