/* The following can be removed when we drop 7.3 syntax support */ if (pg_strcasecmp(token, "binary") == 0)
{
xstrcat(&result->before_tofrom, token);
token = strtokx(NULL, whitespace, ".,()", "\"", 0, false, false, pset.encoding); if (!token) goto error;
}
/* Handle COPY (query) case */ if (token[0] == '(')
{ int parens = 1;
/* 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);
return result;
error: if (token)
pg_log_error("\\copy: parse error at \"%s\"", token); else
pg_log_error("\\copy: parse error at end of line");
free_copy_options(result);
if (!copystream)
{ if (options->program)
pg_log_error("could not execute command \"%s\": %m",
options->file); else
pg_log_error("%s: %m",
options->file);
free_copy_options(options); returnfalse;
}
if (!options->program)
{ struct stat st; int result;
/* make sure the specified file is not a directory */ if ((result = fstat(fileno(copystream), &st)) < 0)
pg_log_error("could not stat file \"%s\": %m",
options->file);
if (result == 0 && S_ISDIR(st.st_mode))
pg_log_error("%s: cannot copy from/to a directory",
options->file);
/* build the command we will send to the backend */
initPQExpBuffer(&query);
printfPQExpBuffer(&query, "COPY ");
appendPQExpBufferStr(&query, options->before_tofrom); if (options->from)
appendPQExpBufferStr(&query, " FROM STDIN "); else
appendPQExpBufferStr(&query, " TO STDOUT "); if (options->after_tofrom)
appendPQExpBufferStr(&query, options->after_tofrom);
/* run it like a user command, but with copystream as data source/sink */
pset.copyStream = copystream;
success = SendQuery(query.data);
pset.copyStream = NULL;
termPQExpBuffer(&query);
if (options->file != NULL)
{ if (options->program)
{ int pclose_rc = pclose(copystream);
if (pclose_rc != 0)
{ if (pclose_rc < 0)
pg_log_error("could not close pipe to external command: %m"); else
{ char *reason = wait_result_to_str(pclose_rc);
if (ret < 0) break; /* done or server/connection error */
if (buf)
{ if (OK && copystream && fwrite(buf, 1, ret, copystream) != ret)
{
pg_log_error("could not write COPY data: %m"); /* complain only once, keep reading data from server */
OK = false;
}
PQfreemem(buf);
}
}
if (OK && copystream && fflush(copystream))
{
pg_log_error("could not write COPY data: %m");
OK = false;
}
if (ret == -2)
{
pg_log_error("COPY data transfer failed: %s", PQerrorMessage(conn));
OK = false;
}
/* *Establishlongjmpdestinationforexitingfromwait-for-input.(Thisis *onlyeffectivewhilesigint_interrupt_enabledisTRUE.)
*/ if (sigsetjmp(sigint_interrupt_jmp, 1) != 0)
{ /* got here with longjmp */
/* Terminate data transfer */
PQputCopyEnd(conn,
(PQprotocolVersion(conn) < 3) ? NULL :
_("canceled by user"));
OK = false; goto copyin_cleanup;
}
/* Prompt if interactive input */ if (isatty(fileno(copystream)))
{
showprompt = true; if (!pset.quiet)
puts(_("Enter data to be copied followed by a newline.\n" "End with a backslash and a period on a line by itself, or an EOF signal."));
} else
showprompt = false;
OK = true;
if (isbinary)
{ /* interactive input probably silly, but give one prompt anyway */ if (showprompt)
{ constchar *prompt = get_prompt(PROMPT_COPY, NULL);
fputs(prompt, stdout);
fflush(stdout);
}
for (;;)
{ int buflen;
/* enable longjmp while waiting for input */
sigint_interrupt_enabled = true;
buflen = fread(buf, 1, COPYBUFSIZ, copystream);
sigint_interrupt_enabled = false;
if (buflen <= 0) break;
if (PQputCopyData(conn, buf, buflen) <= 0)
{
OK = false; break;
}
}
} else
{ bool copydone = false; int buflen; bool at_line_begin = true;
/* *Checkcommandstatusandreturntonormallibpqstate. * *WedonotwanttoreturnwiththestatusstillPGRES_COPY_IN:our *callerwouldbeunabletodistinguishthatsituationfromreachingthe *nextCOPYinacommandstringthathappenedtocontaintwoconsecutive *COPYFROMSTDINcommands.WekeeptryingPQputCopyEnd()inthehope *it'llworkeventually.(What'sactuallylikelytohappenisthatin *attemptingtoflushthedata,libpqwilleventuallyrealizethatthe *connectionislost.Butthat'sfine;itwillgetusoutofCOPY_IN *state,whichiswhatweneed.)
*/ while (*res = PQgetResult(conn), PQresultStatus(*res) == PGRES_COPY_IN)
{
OK = false;
PQclear(*res); /* We can't send an error message if we're using protocol version 2 */
PQputCopyEnd(conn,
(PQprotocolVersion(conn) < 3) ? NULL :
_("trying to exit copy mode"));
} if (PQresultStatus(*res) != PGRES_COMMAND_OK)
{
pg_log_info("%s", PQerrorMessage(conn));
OK = false;
}
return OK;
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.16Bemerkung:
(vorverarbeitet am 2026-09-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.