Re: COPY table_name (single_column) FROM 'unknown.txt' DELIMITER E'\n'

From: "Joel Jacobson" <joel(at)compiler(dot)org>
To: "Daniel Verite" <daniel(at)manitou-mail(dot)org>, Darafei Komяpa Praliaskouski <me(at)komzpa(dot)net>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "Isaac Morland" <isaac(dot)morland(at)gmail(dot)com>, "Chapman Flack" <chap(at)anastigmatix(dot)net>, "PostgreSQL Hackers" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: COPY table_name (single_column) FROM 'unknown.txt' DELIMITER E'\n'
Date: 2021-05-10 06:12:47
Message-ID: 0e451c85-ce2c-4197-91aa-5eecd4f0d3e9@www.fastmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

What about:

COPY ... FROM ... WITH PATTERN 'regexp_pattern'

Where the columns would be matched with the capture groups.

This could handle the quite common case of varying white-space as column separators:

COPY log (col1, col2, col3) FROM 'log.txt' WITH PATTERN '^(\S+)\s+(\S+)\s+(\S+)$'

This could also handle $SUBJECT:

COPY table_name (single_column) FROM 'unknown.txt' WITH PATTERN '^(.*)$';

And lots of other more complex use-cases.

/Joel

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2021-05-10 06:15:06 Re: AlterSubscription_refresh "wrconn" wrong variable?
Previous Message Tom Lane 2021-05-10 06:03:58 Another modest proposal for reducing CLOBBER_CACHE_ALWAYS runtime