<p>Heya,</p>
<p>I'm working to populate a Postgres database using a pg_dump file and I'm getting a syntax error on a COPY FROM stdin line inside the dump. The basic format of the query is like this:</p>
<pre><code>COPY the_thing (id, policy_id, created_at) FROM stdin;
1 3 2016-02-26 18:10:40.193308+00
2 3 2016-02-26 18:10:40.193308+00
3 8 2016-02-26 18:10:40.205101+00
4 8 2016-02-26 18:10:40.205101+00
\.
</code></pre>
<p>And I'm getting this error: pq: syntax error at or near "1" (code = 42601 pos = 12191)</p>
<p>All I'm doing is using ioutil.Readfile to pump the entire pg_dump file into a string, then passing to Exec on the DB object. I've tried using a TX as well, and I can't make a prepared statement as it's multiple statements in the string.</p>
<p>Any ideas? I feel like "stdin" in this context is a misnomer, but I am no expert on this matter. Thoughts?</p>
<p>(edited for formatting)</p>
<hr/>**评论:**<br/><br/>dinkumator: <pre><p>Error message itself is probably due to the semicolon, but... There's a special handler method for bulk imports, you shouldn't use a normal query: <a href="https://godoc.org/github.com/lib/pq#hdr-Bulk_imports" rel="nofollow">https://godoc.org/github.com/lib/pq#hdr-Bulk_imports</a></p>
<p>Although if you dig into the details you might be able to do more (looks like each row will have to be sent over the wire, not in bulk):
<a href="https://github.com/lib/pq/blob/master/copy.go#L20" rel="nofollow">https://github.com/lib/pq/blob/master/copy.go#L20</a></p></pre>junkdrome: <pre><p>I did notice the bulk copy API last night while scrambling around and figured it'd be my huckleberry.</p>
<p>Your response is very appreciated.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传