Re: COPY FROM WHEN condition

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "David Fetter" <david(at)fetter(dot)org>
Cc: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>,"corey(dot)huinker" <corey(dot)huinker(at)gmail(dot)com>,nasbyj(at)amazon(dot)com,"Surafel Temsgen" <surafel3000(at)gmail(dot)com>,"Christoph Moench-Tegeder" <cmt(at)burggraben(dot)net>,"PostgreSQL Hackers" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: COPY FROM WHEN condition
Date: 2018-11-03 12:53:37
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David Fetter wrote:

> It also seems like a violation of separation of concerns to couple
> FEBE to grammar, so there'd need to be some way to do those things
> separately, too.

After re-reading psql/copy.c, I withdraw what I said upthread:
it doesn't appear necessary to add anything to support the WHEN
condition with \copy.

\copy does have a dedicated mini-parser, but it doesn't try to
recognize every option: it's only concerned with getting the bits of
information that are needed to perform the client-side work:
- whether it's a copy from or to
- what exact form and value has the 'filename' argument immediately
after from or to:
'<file path>' | PROGRAM '<command>' | stdin | stdout | pstdout | pstdout

It doesn't really care what the options are, just where they are
in the buffer, so they can be copied into the COPY SQL statement.

From the code:
* The documented syntax is:
* \copy tablename [(columnlist)] from|to filename [options]
* \copy ( query stmt ) to filename [options]

The WHEN clause would be part of the [options], which
are handled as simply as this in parse_slash_copy():

/* Collect the rest of the line (COPY options) */
token = strtokx(NULL, "", NULL, NULL,
0, false, false, pset.encoding);
if (token)
result->after_tofrom = pg_strdup(token);

So unless there's something particular in the WHEN clause
expression that could make this strtokx() invocation error out,
this should work directly.

Best regards,
Daniel Vérité
PostgreSQL-powered mailer:
Twitter: @DanielVerite

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Phil Florent 2018-11-03 13:43:33 RE: Internal error XX000 with enable_partition_pruning=on, pg 11 beta1 on Debian
Previous Message Karsten Hilbert 2018-11-03 12:14:19 Re: backend crash on DELETE, reproducible locally