Re: SQL copy from csv with explicit field ordering

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Terry Fielder <terry(at)greatgulfhomes(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: SQL copy from csv with explicit field ordering
Date: 2001-03-02 16:10:19
Message-ID: Pine.LNX.4.30.0103021706380.775-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmx(dot)net http://yi.org/peter-e/

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tangorre, Michael T. 2001-03-02 16:53:48 Database Question
Previous Message Jan Wieck 2001-03-02 15:34:02 Re: Help creating rules/triggers/functions