Re: COPY FROM WHEN condition - Mailing list pgsql-hackers

From Daniel Verite
Subject Re: COPY FROM WHEN condition
Date
Msg-id c8cee82b-ae71-4153-a29f-fd6f15ff631f@manitou-mail.org
Whole thread Raw
In response to Re: COPY FROM WHEN condition  (David Fetter <david@fetter.org>)
Responses Re: COPY FROM WHEN condition
List 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: http://www.manitou-mail.org
Twitter: @DanielVerite


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: partitioned indexes and tablespaces
Next
From: Phil Florent
Date:
Subject: RE: Internal error XX000 with enable_partition_pruning=on, pg 11beta1 on Debian