0

I am trying to export / import a set of tables from a PostgreSQL database.

I am using psql's copy from with stdin from a script. I have read that data (formerly produced using copy to with stdout) can be read and delimited using the command escape \..

What I didn't get from the documentation clearly is what would happen if \. appears in the formerly exported data.

Specifcally this section of the documentation (emphasis mine) isn't very clear about that.

For \copy ... from stdin, data rows are read from the same source that issued the command, continuing until \. is read or the stream reaches EOF. This option is useful for populating tables in-line within a SQL script file. For \copy ... to stdout, output is sent to the same place as psql command output, and the COPY count command status is not printed (since it might be confused with a data row). To read/write psql's standard input or output regardless of the current command source or \o option, write from pstdin or to pstdout.

Can / must a \. appearing in the data escaped somehow?

I am currently using utf8 encoded text format for the export / import.

1 Answer 1

1

I think I found the relevant information in the documentation of the SQL COPY command (TEXT Format section, again emphasis mine):

End of data can be represented by a single line containing just backslash-period (\.). An end-of-data marker is not necessary when reading from a file, since the end of file serves perfectly well; it is needed only when copying data to or from client applications using pre-3.0 client protocol.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.