COPY and file_fdw with fixed column widths

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: COPY and file_fdw with fixed column widths
Date: 2015-04-28 19:35:39
Message-ID: 20150428193539.GA31725@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I know COPY doesn't support importing files with fixed column widths,
i.e. we can't say field1 is the first 30 characters, and field2 is the
rest of the line. We need a unique delimiter at column 31. (Commercial
Ingres does support this ability.)

I know we tell most people to use sed, Perl, or an ETL tool to convert
files into a format COPY understands, and I think that is a reasonable
answer. However, the file_fdw also reads our COPY format, and in that
case, the data file might be updated regularly and running an ETL
process on it every time it is read is inconvenient.

I asking because I am playing around with file_fdw and I have some log
files with a Unix 'date' prefix, a colon, then some text that might also
contain a colon. It would be ideal if I could read in first 28
characters into field1, then the rest of the line into field2. The only
idea I have is to create a single-column foreign table that reads the
entire line as one field, then a view on top of that the parses the line
into fields, but that seems kind of complex.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-04-28 19:35:55 Re: ATSimpleRecursion() and inheritance foreign parents
Previous Message Alvaro Herrera 2015-04-28 18:44:24 Re: Feedback on getting rid of VACUUM FULL