Re: SQL copy from csv with explicit field ordering - Mailing list pgsql-sql

From Peter Eisentraut
Subject Re: SQL copy from csv with explicit field ordering
Date
Msg-id Pine.LNX.4.30.0103021706380.775-100000@peter.localdomain
Whole thread Raw
In response to SQL copy from csv with explicit field ordering  (Terry Fielder <terry@greatgulfhomes.com>)
List pgsql-sql
Terry Fielder writes:

> Is there somewhere that I can either enable the first line of CSV as
> header names
>
> OR
>
> Can I explicitly define my import field ordering from within the select
> statement?

No and no.  You will have to preprocess your file.  Something like this
will probably do:

#! /bin/sh
IFS=,
cat "inputfile" | \
while read COL1 COL2 COL3; do   echo "$COL3,$COL2,$COL1" >> "outputfile"
done

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



pgsql-sql by date:

Previous
From: Thomas Lockhart
Date:
Subject: Re: [HACKERS] why the DB file size does not reduce when 'delete' the data in DB?
Next
From: Stephan Szabo
Date:
Subject: Re: Help creating rules/triggers/functions