Stanley_Liu
Stanley_Liu

Reputation: 1

Postgres using FOREIGN TABLE and data include "\"

My text file look like:

\home\stanley:123456789
c:/kobe:213
\tej\home\ant:222312

and create FOREIGN TABLE Steps:

CREATE FOREIGN TABLE file_check(txt text) SERVER file_server OPTIONS (format 'text', filename '/home/stanley/check.txt');

after select file_check (using: select * from file_check)

my console show me

homestanley:123456789
c:/kobe:213
ejhomeant:222312

Anyone can help me??

Upvotes: 0

Views: 315

Answers (1)

Richard Huxton
Richard Huxton

Reputation: 22893

The file foreign-data-wrapper uses the same rules as COPY (presumably because it's the same code underneath). You've got to consider that backslash is an escape character...

http://www.postgresql.org/docs/9.2/static/sql-copy.html

Any other backslashed character that is not mentioned in the above table will be taken to represent itself. However, beware of adding backslashes unnecessarily, since that might accidentally produce a string matching the end-of-data marker (.) or the null string (\N by default). These strings will be recognized before any other backslash processing is done.

So you'll either need to double-up the backslashes or perhaps try it as a single-column csv file and see if that helps

Upvotes: 1

Related Questions