2015-03-11 2 views
0

Я пытаюсь импортировать таблицы базы данных на сервер базы данных 9.3.5 Postgres с помощью команды COPY следующим образом:Ошибки импортирующих данных с помощью COPY COMAND в PostgreSQL 9.3.5

COPY comment (generatedid, id, "timestamp", message, bugreport_id, personcontainer_id) FROM stdin; 
    1 12840538 2010-03-03 09:50:46 How is that an error in HttpClient? Don't buffer large content in memory, or configure memory in your VM appropriately. HTTPCLIENT-922 102 
    2 12841503 2010-03-04 21:36:13 Thanks for having a look!<br/><br/>I explored and found problem is with org.apache.james.mime4j.util.CharsetUtil of mime4j jar. It tries to load all available charset classes present under JVM.<br/><br/>I know memory for Perm Gen can be increased but there would be limit. I have increased it and would be doing a round of load testing. If it still consumes whole allocated space I would be putting some fix on CharsetUtil.<br/><br/>Stack trace for reference:<br/>-----------------------------------------<br/>java.lang.OutOfMemoryError: PermGen space<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at sun.nio.cs.ext.IBM970$Encoder.&lt;clinit&gt;(IBM970.java:2688)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at sun.nio.cs.ext.IBM970.newEncoder(IBM970.java:45)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at java.lang.StringCoding$StringEncoder.&lt;init&gt;(StringCoding.java:215)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at java.lang.StringCoding$StringEncoder.&lt;init&gt;(StringCoding.java:207)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at java.lang.StringCoding.encode(StringCoding.java:266)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at java.lang.String.getBytes(String.java:947)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at org.apache.james.mime4j.util.CharsetUtil.&lt;clinit&gt;(CharsetUtil.java:1028)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at org.apache.http.entity.mime.MIME.&lt;clinit&gt;(MIME.java:51)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at org.apache.http.entity.mime.HttpMultipart.&lt;clinit&gt;(HttpMultipart.java:85)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at org.apache.http.entity.mime.MultipartEntity.&lt;init&gt;(MultipartEntity.java:78)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at org.apache.http.entity.mime.MultipartEntity.&lt;init&gt;(MultipartEntity.java:101)<br/><br/> HTTPCLIENT-922 103 

Но у меня есть ошибки во всех импортируемых данных (Я терплю только 2 строки данных, указанных выше, чтобы показать все ошибки вообще пути), как:

ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "}" 
    LINE 1: }<br/>&nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "break" 
    LINE 1: break; 
    ^
    ERROR: syntax error at or near "<" 
    LINE 1: <br/><br/>Recompiling after this change and trying again the... 
    ^
    ERROR: syntax error at or near "ll" 
    LINE 1: ll provide a fix for CVS<br/>HEAD tomorrow. My apologies.<br... 
    ^
    ERROR: syntax error at or near "Cookie" 
    LINE 1: Cookie&#39; 
    ^
    ERROR: syntax error at or near "headers" 
    LINE 1: headers only.<br/><br/>Oleg HTTPCLIENT-292 28066 
    ^
    ERROR: syntax error at or near "t" 
    LINE 1: t had a chance to try this patch out, but if it works for yo... 
    ^
    ERROR: syntax error at or near "s" 
    LINE 1: s<br/>good enough for me.<br/><br/>Mike HTTPCLIENT-292 28068 
    ^
    ERROR: syntax error at or near "d" 
    LINE 1: d feel better if someone else had a look.<br/><br/>Oleg HTTP... 
    ^
    ERROR: syntax error at or near "ll" 
    LINE 1: ll try to come up with something more elegant for the 2.1 br... 
    ^
    ERROR: syntax error at or near "t" 
    LINE 1: t think either<br/>patch 2 or 3 handles this case, unless (i... 
    ^
    ERROR: syntax error at or near "What" 
    LINE 1: What we really need is a way to remove NTLM headers after th... 
    ^
    ERROR: syntax error at or near "authentication" 
    LINE 1: authentication has succeeded.<br/>Agreed. However, that stil... 
    ^
    ERROR: syntax error at or near "<" 
    LINE 1: <br/>if (&quot;NTLM&quot;.equalsIgnoreCase(authscheme.getSch... 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "//" 
    LINE 1: // clean up<br/>}<br/><br/>As far as HEAD CVS goes, there ar... 
    ^
    ERROR: syntax error at or near "t" 
    LINE 1: t not<br/>pretty, but that appears to be the only option we ... 
    ^
    ERROR: syntax error at or near "ll" 
    LINE 1: ll be working on a more elegant fix for the CVS HEAD<br/><br... 
    ^
    ERROR: syntax error at or near "s" 
    LINE 1: s the only real choice for 2.0.<br/><br/>Mike HTTPCLIENT-292... 
    ^
    ERROR: syntax error at or near "m" 
    LINE 1: m currently unable to test it and it could take a couple of ... 
    ^
    ERROR: syntax error at or near "Digest" 
    LINE 1: Digest schemes still need to be refactored to take<br/>advan... 
    ^
    ERROR: syntax error at or near "code" 
    LINE 1: code&gt; 
    ^
    ERROR: syntax error at or near "public" 
    LINE 1: public OutputStream getRequestOutputStream(boolean <br/>useC... 
    ^
    ERROR: syntax error at or near "/" 
    LINE 1: /code&gt; 
    ^
    ERROR: syntax error at or near "<" 
    LINE 1: <br/><br/>The PutMethod does allow for chunking with the fun... 
    ^
    ERROR: syntax error at or near "code" 
    LINE 1: code&gt; 
    ^
    unrecognized boolean value; assuming "on". 
    Showing only tuples. 
    \t: extra argument "Jun" ignored 
    \t: extra argument "02" ignored 
    \t: extra argument "00:39:55" ignored 
    \t: extra argument "GMT+00:00" ignored 
    \t: extra argument "20090)" ignored 
    \t: extra argument "seems" ignored 
    \t: extra argument "broken.<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;[java]" ignored 
    \t: extra argument "2009/06/02" ignored 
    \t: extra argument "13:14:12:150" ignored 
    \t: extra argument "CEST" ignored 
    \t: extra argument "[DEBUG]" ignored 
    \t: extra argument "SingleClientConnManager" ignored 
    \t: extra argument "-" ignored 
    \t: extra argument "Get" ignored 
    \t: extra argument "connection" ignored 
    \t: extra argument "for" ignored 
    \t: extra argument "route" ignored 
    \t: extra argument "HttpRoute[{}-&gt;<a" ignored 
    \t: extra argument "href="http://www.seoconsultants.com">http://www.seoconsultants.com</a>]<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[java]" ignored 
    \t: extra argument "2009/06/02" ignored 
    \t: extra argument "13:14:12:334" ignored 
    \t: extra argument "CEST" ignored 
    \t: extra argument "[DEBUG]" ignored 
    \t: extra argument "ClientParamsStack" ignored 
    \t: extra argument "-" ignored 
    \t: extra argument "&#39;http.tcp.nodelay&#39;:" ignored 
    \t: extra argument "true<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[java]" ignored 
    \t: extra argument "2009/06/02" ignored 
    \t: extra argument "13:14:12:335" ignored 
    \t: extra argument "CEST" ignored 
    \t: extra argument "[DEBUG]" ignored 
    \t: extra argument "ClientParamsStack" ignored 
    \t: extra argument "-" ignored 
    \t: extra argument "&#39;http.socket.buffer-size&#39;:" ignored 
    \t: extra argument "8192<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[java]" ignored 
    \t: extra argument "2009/06/02" ignored 
    \t: extra argument "13:14:12:360" ignored 
    \t: extra argument "CEST" ignored 
    \t: extra argument "[DEBUG]" ignored 
    \t: extra argument "ClientParamsStack" ignored 
    \t: extra argument "-" ignored 
    \t: extra argument "&#39;http.protocol.version&#39;:" ignored 
    \t: extra argument "HTTP/1.1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[java]" ignored 
    \t: extra argument "2009/06/02" ignored 
    \t: extra argument "13:14:12:361" ignored 
    \t: extra argument "CEST" ignored 
    \t: extra argument "[DEBUG]" ignored 
    \t: extra argument "ClientParamsStack" ignored 
    \t: extra argument "-" ignored 
    \t: extra argument "&#39;http.useragent&#39;:" ignored 
    \t: extra argument "Mozilla/5.0" ignored 
    \t: extra argument "(Macintosh;" ignored 
    \t: extra argument "U;" ignored 
    \t: extra argument "Intel" ignored 
    \t: extra argument "Mac" ignored 
    \t: extra argument "OS" ignored 
    \t: extra argument "X" ignored 
    \t: extra argument "10.5;" ignored 
    \t: extra argument "en-US;" ignored 
    \t: extra argument "rv:1.9.0.10)" ignored 
    \t: extra argument "Gecko/2009042315" ignored 
    \t: extra argument "Firefox/3.0.10<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[java]" ignored 
    \t: extra argument "2009/06/02" ignored 
    \t: extra argument "13:14:12:362" ignored 
    \t: extra argument "CEST" ignored 
    \t: extra argument "[DEBUG]" ignored 
    \t: extra argument "RequestAddCookies" ignored 
    \t: extra argument "-" ignored 
    \t: extra argument "CookieSpec" ignored 
    \t: extra argument "selected:" ignored 
    \t: extra argument "best-match<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[java]" ignored 
    \t: extra argument "2009/06/02" ignored 
    \t: extra argument "13:14:12:362" ignored 
    \t: extra argument "CEST" ignored 
    \t: extra argument "[DEBUG]" ignored 
    \t: extra argument "DefaultClientConnection" ignored 
    \t: extra argument "-" ignored 
    \t: extra argument "Connection" ignored 
    \t: extra argument "shut" ignored 
    \t: extra argument "down<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[java]" ignored 
    \t: extra argument "2009/06/02" ignored 
    \t: extra argument "13:14:12:363" ignored 
    \t: extra argument "CEST" ignored 
    \t: extra argument "[DEBUG]" ignored 
    \t: extra argument "SingleClientConnManager" ignored 
    \t: extra argument "-" ignored 
    \t: extra argument "Releasing" ignored 
    \t: extra argument "connection" ignored 
    \t: extra argument "org.apache.http.impl.conn.SingleClientConnManager$<a" ignored 
    \t: extra argument "href='mailto:[email protected]'>[email protected]</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[java]" ignored 
    \t: extra argument "Exception" ignored 
    \t: extra argument "in" ignored 
    \t: extra argument "thread" ignored 
    \t: extra argument "&quot;main&quot;" ignored 
    \t: extra argument "java.lang.ClassCastException:" ignored 
    \t: extra argument "org.apache.http.auth.AuthSchemeRegistry<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp [java]" ignored 
    invalid command \tat 
    ERROR: syntax error at or near "conn" 
    LINE 1: conn.getRequestOutputStream((isHttp11() &amp;&amp; (null == ... 
    ^
    ERROR: syntax error at or near "ve" 
    LINE 1: ve made something wrong in compilation process because the c... 
    ^
    ERROR: syntax error at or near "d" 
    LINE 1: d attached successfully works in production nowadays. HTTPCL... 
    ^
    invalid command \ 
    ERROR: syntax error at or near "ve" 
    LINE 1: ve tried to use your code. I downloaded the source code of H... 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "Roland" 
    LINE 1: Roland<br/> HTTPCLIENT-579 28761 
    ^
    ERROR: syntax error at or near "s" 
    LINE 1: s not a problem for me to provide a totally functioning exam... 
    ^
    ERROR: syntax error at or near "t" 
    LINE 1: t attach example in this topic because it&#39; 
    ^
    ERROR: syntax error at or near "s" 
    LINE 1: s closed.<br/><br/>Just send me your emails in a private mes... 
    ^
    ERROR: syntax error at or near "ll" 
    LINE 1: ll share the example.<br/> HTTPCLIENT-579 28762 
    ^
    ERROR: syntax error at or near "ve" 
    LINE 1: ve added a patch to the code you provided above to handle th... 
    ^
    ERROR: syntax error at or near "Require" 
    LINE 1: Require NTLMv2 session security&quot; 
    ^
    ERROR: syntax error at or near "is" 
    LINE 1: is set as an option inside &quot; 
    ^
    ERROR: syntax error at or near "Network" 
    LINE 1: Network security: Minimum session security for NTLM SSP base... 
    ^
    ERROR: syntax error at or near "." 
    LINE 1: .<br/><br/>The changes I made were a result of reading of: <... 
    ^
    ERROR: syntax error at or near "d" 
    LINE 1: d happily licence my change under the Apache Licence, I don&... 
    ^
    ERROR: syntax error at or near "t" 
    LINE 1: t believe it&#39; 
    ^
    ERROR: syntax error at or near "s" 
    LINE 1: s allowed as the original patch was under the LGPL.<br/><br/... 
    ^
    ERROR: syntax error at or near "s" 
    LINE 1: s request that we can create an external project (on sourcef... 
    ^
    ERROR: syntax error at or near "m" 
    LINE 1: m running the same issue like Zhao had. What was the resolu... 
    ^
    ERROR: syntax error at or near "s" 
    LINE 1: s unclear about resolution &#39; 
    ^
    ERROR: syntax error at or near "Won" 
    LINE 1: Won&#39; 
    ^
    ERROR: syntax error at or near "t" 
    LINE 1: t Fix &#39; 
    ^
    ERROR: syntax error at or near "?<" 
    LINE 1: ?<br/><br/>However, HttpClient 4.0 is capable of supporting ... 
    ^
    ERROR: syntax error at or near "s" 
    LINE 1: s not illegal. It&#39; 
    ^
    ERROR: syntax error at or near "s" 
    LINE 1: s just that you create a package that is probably no longer ... 
    ^
    ERROR: syntax error at or near "s" 
    LINE 1: s the reason why we cannot provide this out of the box. What... 
    ^
    ERROR: syntax error at or near "s" 
    LINE 1: s license terms you will need to check with a software licen... 
    ^
    ERROR: syntax error at or near "ve" 
    LINE 1: ve decided to attach complete example of integration Axis, H... 
    ^
    ERROR: syntax error at or near "d" 
    LINE 1: d recommend you before sending your requests to figure out h... 
    ^
    ERROR: syntax error at or near "s" 
    LINE 1: s the problem? HTTPCLIENT-579 28773 
    ^
    ERROR: syntax error at or near "project" 
    LINE 1: project name=&quot; 
    ^
    ERROR: syntax error at or near "casau" 
    LINE 1: casau&quot; 
    ^
    ERROR: syntax error at or near "default" 
    LINE 1: default=&quot; 
    ^
    ERROR: syntax error at or near "main" 
    LINE 1: main&quot; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &gt; 
    ^
    ERROR: syntax error at or near "<" 
    LINE 1: <br/>&nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &lt; 
    ^
    ERROR: syntax error at or near "target" 
    LINE 1: target name=&quot; 
    ^
    ERROR: syntax error at or near "main" 
    LINE 1: main&quot; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &gt; 
    ^
    ERROR: syntax error at or near "<" 
    LINE 1: <br/>&nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &lt; 
    ^
    ERROR: syntax error at or near "javac" 
    LINE 1: javac srcdir=&quot; 
    ^
    ERROR: syntax error at or near "." 
    LINE 1: .&quot; 
    ^
    ERROR: syntax error at or near "destdir" 
    LINE 1: destdir=&quot; 
    ^
    ERROR: syntax error at or near "." 
    LINE 1: .&quot; 
    ^
    ERROR: syntax error at or near "deprecation" 
    LINE 1: deprecation=&quot; 
    ^
    ERROR: syntax error at or near "yes" 
    LINE 1: yes&quot; 
    ^
    ERROR: syntax error at or near "debug" 
    LINE 1: debug=&quot; 
    ^
    ERROR: syntax error at or near "yes" 
    LINE 1: yes&quot; 
    ^
    ERROR: syntax error at or near "<" 
    LINE 1: <br/>&nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "classpath" 
    LINE 1: classpath=&quot; 
    ^
    ERROR: syntax error at or near ".." 
    LINE 1: ../lib/commons-logging-1.0.4.jar; 
    ^
    ERROR: syntax error at or near ".." 
    LINE 1: ../lib/commons-codec-1.3.jar; 
    ^
    ERROR: syntax error at or near ".." 
    LINE 1: ../lib/commons-httpclient-3.0-ntlm-2.0.jar&quot; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &gt; 
    ^
    ERROR: syntax error at or near "<" 
    LINE 1: <br/>&nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &nbsp; 
    ^
    ERROR: syntax error at or near "&" 
    LINE 1: &lt; 
    ^
    ERROR: syntax error at or near "include" 
    LINE 1: include name=&quot; 
    ^
    ERROR: syntax error at or near "**" 
    LINE 1: **/*.java&quot;/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/javac&... 
^

Как я могу избежать этих ошибок? Могу ли я решить все ошибки, используя только один вид изменений в команде COPY или импортируемых данных?

+1

Работает здесь (после преобразования пробелов в закладки в нужных местах) – wildplasser

+0

Как это сделать? @wildplasser –

+0

Для двух строк выборки я сделал это вручную. Для нетривиальных сумм вы должны сначала попытаться сгенерировать правильные данные (с вкладками в качестве разделителей) (я предполагаю, что файл был сгенерирован дамп-программой) и избегать редакторов, которые молча конвертируют вкладки в пробелы. – wildplasser

ответ

0

Нижеприведенная программа очистит входные данные.

  • Он работает на двух тестовых линий в вопросе
  • для увеличения ввода может потребоваться некоторые дополнительные настройки.
  • Позаботьтесь о том, чтобы в начале строк не было начального пространства.
  • Если производительность необходима: сделайте функции статическими, и они будут вставлены.

#include <stdio.h> 
#include <string.h> 

/** 
** cleantab.c: correct tab-separated dumpfile in which tabs have been expanded 
** to spaces. 
** input is from stdin; output goes to stdout. 
** Note : space and tab in the input are seen as single whithespace, 
** so multipe tabs *without* non whites betweesn them are merged into ones 
** (for the Postgres .tsv file this could only happen on fields 
** that originally were NULL) 
**/

/** Test data 
1  42 2015-03-13 12:12:13   wat the fuck &#sssdd hiero </html> nog-een-string  13 
2  442 2015-03-13 13:13:13  wat the sia uck &#nss dd daaro </html>kut nog-een-string 13 
*/ 

char bigbuff[1024*1024]; 

struct witje { 
     size_t off; 
     size_t len; 
     } witjes[16*1024]; 

size_t parse_line(char *str, struct witje *arr); 
void dump_chunks(char *str, struct witje *arr, size_t nwit); 
void dump_nchar(char *str, size_t nchar); 
void dump_nchar_notab(char *str, size_t nchar); 

int main(void) 
{ 
size_t nwit,iwit; 

for (; fgets(bigbuff, sizeof bigbuff, stdin);) { 
     nwit = parse_line(bigbuff, witjes); 

#if 0 
     for (iwit = 0; iwit < nwit; iwit++) { 
       fprintf(stderr,"[%zu] %zu+%zu\n" 
       , iwit, witjes[iwit].off , witjes[iwit].len); 
       } 
#endif 
     dump_chunks(bigbuff, witjes , nwit); 
     } 

return 0; 
} 
size_t parse_line(char *str, struct witje *arr) 
{ 
size_t len, pos, idx; 

for(len= pos= idx=0; str[pos]; pos += len) { 
     arr[idx].off = pos;  /* position of whitespace */ 
     len = strspn(str+pos, " \t\n\r"); 
     pos += len; 
     arr[idx++].len = len; /* length of whitespace */ 
     len = strcspn(str+pos, " \t\n\r"); 
     } 
return idx; 
} 

void dump_chunks(char *str, struct witje *arr, size_t nwit) 
{ 
size_t iwit, pos; 

for (pos= iwit = 0; iwit < nwit; iwit++) { 
     // if (iwit ==0 && arr[iwit].off == 0 && arr[iwit].len ==0) { iwit++; nwit--; continue; } 
     if (arr[iwit].off >pos) dump_nchar(str+pos, arr[iwit].off -pos);  /* payload */ 
     pos = arr[iwit].off ; 
     if (arr[iwit].len) switch (iwit) { 
     case 0: 
     case 1: 
     case 2: 
       dump_nchar("\t", 1); /* tab */ 
       break; 
     case 3: 
       dump_nchar(" ", 1);  /* the space between date and time*/ 
       break; 
     default: 
       if (iwit == nwit -1) dump_nchar("\n", 1);  /* nl */ 
       else if (iwit >= nwit -3) dump_nchar("\t", 1); /* tab */ 
       else dump_nchar_notab(str+pos, arr[iwit].len) ; /* whitespace */ 
       break; 
       } 
     pos += arr[iwit].len ; 
     } 
} 

void dump_nchar(char *str, size_t nchar) { 
while (nchar--) putc(*str++, stdout); 
} 

void dump_nchar_notab(char *str, size_t nchar) { 
for (;nchar--; str++) putc(*str == '\t' ? ' ' : *str, stdout); 
} 
+0

Благодарим вас за код, указанный выше. @wildplasser –

0

Я не знаю, как, но я решил с одной странной команды для ситуации: GRANT ALL ON SCHEMA schema_name К psql_roler_name. После того, как я набрал команду restore и работал нормально. Может ли кто-нибудь объяснить мне это?

+0

Ну, скорее всего, строки **, предшествующие тем, которые вы показали **, создали схему и изменили путь search_path к ней, но текущему сеансу не разрешили использовать эту конкретную схему. – wildplasser

+0

Строки, предшествующие команде SET SEARCH_PATH, но не имеют CREATE SCHEMA. У них также есть команда CREATE TABLE. –

Смежные вопросы