从text.rpt文件复制数据以将其粘贴到pgadmin中 [英] copy data from a text.rpt file to paste it postgresql in pgadmin

查看:222
本文介绍了从text.rpt文件复制数据以将其粘贴到pgadmin中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我跑步时:

COPY con (date,kgs) 
FROM 'H:Sir\\data\\reporting\\hi.rpt'
WITH DELIMITER ','
CSV HEADER 
    date AS 'Datum/Uhrzeit'
    kgs  AS 'Summe'

我得到了错误:

WARNING:  nonstandard use of \\ in a string literal
LINE 2: FROM 'H:Sudhir\\Conair data\\TBreporting\\hi.txt'
             ^
HINT:  Use the escape string syntax for backslashes, e.g., E'\\'.

我这个问题已经有一段时间了.帮助吗?

I've been having this problem for quite a while. Help?

推荐答案

这不是错误,只是警告.它与文件内容无关,它与PostgreSQL设置和您使用的COPY命令语法有关.

It's not an error, it's just a warning. It has nothing to do with the file content, it's related to a PostgreSQL setting and the COPY command syntax you're using.

您使用的是8.1以后的PostgreSQL,而standard_conforming_strings处于关闭状态-9.1之前的版本(默认为关闭),或者是手动关闭的较新版本.

You're using PostgreSQL after 8.1 with standard_conforming_strings turned off - either before 9.1 (which defaulted to off) or a newer version with it turned off manually.

这会导致字符串中的反斜杠(如bob\ted)被解释为转义符,因此,字符串将是带有文字制表符的bob<tab>ted,因为\t是制表符的转义符.

This causes backslashes in strings, like bob\ted, get interpreted as escapes, so that string would be bob<tab>ted with a literal tab, as \t is the escape for a tab.

解释这样的字符串与SQL标准相反,SQL标准没有C样式的反斜杠转义符.几年前,PostgreSQL团队决定切换到SQL标准的处理方式.出于向后兼容的原因,它分两个阶段完成:

Interpreting strings like this is contrary to the SQL standard, which doesn't have C-style backslash escapes. Years ago the PostgreSQL team decided to switch to the SQL standard way of doing things. For backward compatibility reasons it was done in two stages:

  • 添加standard_conforming_strings选项以使用SQL标准的字符串解释,但默认将其设置为off.使用非标准PostgreSQL字符串解释时发出警告.添加新的E'string'样式,以允许应用程序显式请求字符串中的转义处理.

  • Add the standard_conforming_strings option to use the SQL-standard interpretation of strings, but have it default to off. Issue warnings when using the non-standard PostgreSQL string interpretation. Add a new E'string' style to allow applications to explicitly request escape processing in strings.

稍后发布的一些版本,一旦人们更新并修复了其应用程序产生的警告,则默认情况下将standard_conforming_strings打开.应该.

A few releases later, turn standard_conforming_strings on by default, once people had updated and fixed the warnings their applications produced. Supposedly.

\的转义符是\\.因此,像您一样(或您正在使用的工具)将反斜杠加倍"是正确的. PostgreSQL正在显示警告,因为它不知道在编写H:Sir\\data\\reporting\\hi.rpt时是按字面意思H:Sir\\data\\reporting\\hi.rpt(如SQL规范所述)还是H:Sir\data\reporting\hi.rpt(如PostgreSQL曾经这样做,违反标准).

The escape for \ is \\. So "doubling" the backslashes like you (or the tool you're using) done is correct. PostgreSQL is showing a warning because it doesn't know if when you wrote H:Sir\\data\\reporting\\hi.rpt you meant literally H:Sir\\data\\reporting\\hi.rpt (like the SQL spec says) or H:Sir\data\reporting\hi.rpt (like PostgreSQL used to do, against the standard).

因此,您的查询没有任何问题.如果要消除警告,请打开standard_conforming_strings,或在字符串中添加一个明确的E''.

Thus there's nothing wrong with your query. If you want to get rid of the warning, either turn standard_conforming_strings on , or add an explicit E'' to your string.

这篇关于从text.rpt文件复制数据以将其粘贴到pgadmin中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆