copy-from-2.pt 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. send
  2. Query {"query": "DROP TABLE IF EXISTS t"}
  3. ----
  4. until ignore=NoticeResponse
  5. ReadyForQuery
  6. ----
  7. CommandComplete {"tag":"DROP TABLE"}
  8. ReadyForQuery {"status":"I"}
  9. send
  10. Query {"query": "CREATE TABLE t (i INT8, t TEXT)"}
  11. ----
  12. until
  13. ReadyForQuery
  14. ----
  15. CommandComplete {"tag":"CREATE TABLE"}
  16. ReadyForQuery {"status":"I"}
  17. # COPY with both empty string and \N for NULL.
  18. # Note that after receiving the terminating char, no other data should be
  19. # accepted.
  20. send
  21. Query {"query": "COPY t FROM STDIN"}
  22. CopyData "1\tblah\n"
  23. CopyData "2\t\n"
  24. CopyData "3\t\\N\n"
  25. CopyData "\\.\n"
  26. CopyDone
  27. Query {"query": "SELECT * FROM t ORDER BY i"}
  28. ----
  29. until
  30. ReadyForQuery
  31. ReadyForQuery
  32. ----
  33. CopyIn {"format":"text","column_formats":["text","text"]}
  34. CommandComplete {"tag":"COPY 3"}
  35. ReadyForQuery {"status":"I"}
  36. RowDescription {"fields":[{"name":"i"},{"name":"t"}]}
  37. DataRow {"fields":["1","blah"]}
  38. DataRow {"fields":["2",""]}
  39. DataRow {"fields":["3","NULL"]}
  40. CommandComplete {"tag":"SELECT 3"}
  41. ReadyForQuery {"status":"I"}
  42. # Wrong number of columns.
  43. send
  44. Query {"query": "COPY t FROM STDIN"}
  45. CopyData "1\n"
  46. CopyData "\\.\n"
  47. CopyDone
  48. ----
  49. until err_field_typs=C
  50. ErrorResponse
  51. ReadyForQuery
  52. ----
  53. CopyIn {"format":"text","column_formats":["text","text"]}
  54. ErrorResponse {"fields":[{"typ":"C","value":"22P04"}]}
  55. ReadyForQuery {"status":"I"}
  56. # Verify that only one COPY can run at once.
  57. send
  58. Query {"query": "COPY t FROM STDIN"}
  59. Query {"query": "COPY t FROM STDIN"}
  60. ----
  61. until err_field_typs=C
  62. ErrorResponse
  63. ReadyForQuery
  64. ----
  65. CopyIn {"format":"text","column_formats":["text","text"]}
  66. ErrorResponse {"fields":[{"typ":"C","value":"08P01"}]}
  67. ReadyForQuery {"status":"I"}
  68. # Verify that after a COPY has started another statement cannot run.
  69. send
  70. Query {"query": "COPY t FROM STDIN"}
  71. Query {"query": "SELECT 2"}
  72. ----
  73. until err_field_typs=C
  74. ErrorResponse
  75. ReadyForQuery
  76. ----
  77. CopyIn {"format":"text","column_formats":["text","text"]}
  78. ErrorResponse {"fields":[{"typ":"C","value":"08P01"}]}
  79. ReadyForQuery {"status":"I"}
  80. send
  81. Query {"query": "DROP TABLE t"}
  82. Query {"query": "CREATE TABLE t (i INT8, t TEXT)"}
  83. Query {"query": "COPY t FROM STDIN"}
  84. CopyData "1\tblah\n"
  85. CopyData "\\.\n"
  86. CopyDone
  87. Query {"query": "SELECT * FROM t ORDER BY i"}
  88. ----
  89. until
  90. ReadyForQuery
  91. ReadyForQuery
  92. ReadyForQuery
  93. ReadyForQuery
  94. ----
  95. CommandComplete {"tag":"DROP TABLE"}
  96. ReadyForQuery {"status":"I"}
  97. CommandComplete {"tag":"CREATE TABLE"}
  98. ReadyForQuery {"status":"I"}
  99. CopyIn {"format":"text","column_formats":["text","text"]}
  100. CommandComplete {"tag":"COPY 1"}
  101. ReadyForQuery {"status":"I"}
  102. RowDescription {"fields":[{"name":"i"},{"name":"t"}]}
  103. DataRow {"fields":["1","blah"]}
  104. CommandComplete {"tag":"SELECT 1"}
  105. ReadyForQuery {"status":"I"}
  106. send
  107. Query {"query": "DROP TABLE t"}
  108. Query {"query": "CREATE TABLE t (i INT8, t TEXT)"}
  109. Query {"query": "COPY t FROM STDIN WITH (DELIMITER ',')"}
  110. CopyData "1,blah\n"
  111. CopyData "2,\\N\n"
  112. CopyData "\\.\n"
  113. CopyDone
  114. Query {"query": "SELECT * FROM t ORDER BY i"}
  115. ----
  116. until
  117. ReadyForQuery
  118. ReadyForQuery
  119. ReadyForQuery
  120. ReadyForQuery
  121. ----
  122. CommandComplete {"tag":"DROP TABLE"}
  123. ReadyForQuery {"status":"I"}
  124. CommandComplete {"tag":"CREATE TABLE"}
  125. ReadyForQuery {"status":"I"}
  126. CopyIn {"format":"text","column_formats":["text","text"]}
  127. CommandComplete {"tag":"COPY 2"}
  128. ReadyForQuery {"status":"I"}
  129. RowDescription {"fields":[{"name":"i"},{"name":"t"}]}
  130. DataRow {"fields":["1","blah"]}
  131. DataRow {"fields":["2","NULL"]}
  132. CommandComplete {"tag":"SELECT 2"}
  133. ReadyForQuery {"status":"I"}
  134. send
  135. Query {"query": "DROP TABLE t"}
  136. Query {"query": "CREATE TABLE t (i INT8, t TEXT)"}
  137. Query {"query": "COPY t FROM STDIN WITH (NULL 'NS')"}
  138. CopyData "1\tblah\n"
  139. CopyData "2\t\\N\n"
  140. CopyData "3\tNS\n"
  141. CopyData "\\.\n"
  142. CopyDone
  143. Query {"query": "SELECT * FROM t ORDER BY i"}
  144. ----
  145. until
  146. ReadyForQuery
  147. ReadyForQuery
  148. ReadyForQuery
  149. ReadyForQuery
  150. ----
  151. CommandComplete {"tag":"DROP TABLE"}
  152. ReadyForQuery {"status":"I"}
  153. CommandComplete {"tag":"CREATE TABLE"}
  154. ReadyForQuery {"status":"I"}
  155. CopyIn {"format":"text","column_formats":["text","text"]}
  156. CommandComplete {"tag":"COPY 3"}
  157. ReadyForQuery {"status":"I"}
  158. RowDescription {"fields":[{"name":"i"},{"name":"t"}]}
  159. DataRow {"fields":["1","blah"]}
  160. DataRow {"fields":["2","N"]}
  161. DataRow {"fields":["3","NULL"]}
  162. CommandComplete {"tag":"SELECT 3"}
  163. ReadyForQuery {"status":"I"}
  164. send
  165. Query {"query": "COPY t FROM STDIN"}
  166. CopyData "1\n"
  167. CopyData "\\.\n"
  168. CopyDone
  169. ----
  170. until err_field_typs=C
  171. ErrorResponse
  172. ReadyForQuery
  173. ----
  174. CopyIn {"format":"text","column_formats":["text","text"]}
  175. ErrorResponse {"fields":[{"typ":"C","value":"22P04"}]}
  176. ReadyForQuery {"status":"I"}
  177. send
  178. Query {"query": "DROP TABLE t"}
  179. Query {"query": "CREATE TABLE t (i INT8, t TEXT)"}
  180. Query {"query": "COPY t FROM STDIN WITH (DELIMITER ',')"}
  181. CopyData "1,blah\n"
  182. CopyData "2,\n"
  183. CopyData "\\.\n"
  184. CopyDone
  185. Query {"query": "SELECT * FROM t ORDER BY i"}
  186. ----
  187. until
  188. ReadyForQuery
  189. ReadyForQuery
  190. ReadyForQuery
  191. ReadyForQuery
  192. ----
  193. CommandComplete {"tag":"DROP TABLE"}
  194. ReadyForQuery {"status":"I"}
  195. CommandComplete {"tag":"CREATE TABLE"}
  196. ReadyForQuery {"status":"I"}
  197. CopyIn {"format":"text","column_formats":["text","text"]}
  198. CommandComplete {"tag":"COPY 2"}
  199. ReadyForQuery {"status":"I"}
  200. RowDescription {"fields":[{"name":"i"},{"name":"t"}]}
  201. DataRow {"fields":["1","blah"]}
  202. DataRow {"fields":["2",""]}
  203. CommandComplete {"tag":"SELECT 2"}
  204. ReadyForQuery {"status":"I"}
  205. send
  206. Query {"query": "DROP TABLE t"}
  207. Query {"query": "CREATE TABLE t (i INT8, t TEXT)"}
  208. Query {"query": "COPY t FROM STDIN WITH (NULL 'NS', DELIMITER '|')"}
  209. CopyData "1|blah\n"
  210. CopyData "2|NS\n"
  211. CopyData "3|\n"
  212. CopyData "\\.\n"
  213. CopyDone
  214. Query {"query": "SELECT * FROM t ORDER BY i"}
  215. ----
  216. until
  217. ReadyForQuery
  218. ReadyForQuery
  219. ReadyForQuery
  220. ReadyForQuery
  221. ----
  222. CommandComplete {"tag":"DROP TABLE"}
  223. ReadyForQuery {"status":"I"}
  224. CommandComplete {"tag":"CREATE TABLE"}
  225. ReadyForQuery {"status":"I"}
  226. CopyIn {"format":"text","column_formats":["text","text"]}
  227. CommandComplete {"tag":"COPY 3"}
  228. ReadyForQuery {"status":"I"}
  229. RowDescription {"fields":[{"name":"i"},{"name":"t"}]}
  230. DataRow {"fields":["1","blah"]}
  231. DataRow {"fields":["2","NULL"]}
  232. DataRow {"fields":["3",""]}
  233. CommandComplete {"tag":"SELECT 3"}
  234. ReadyForQuery {"status":"I"}
  235. send
  236. Query {"query": "COPY t FROM STDIN WITH (DELIMITER ',')"}
  237. CopyData "1\n"
  238. CopyData "\\.\n"
  239. CopyDone
  240. ----
  241. until err_field_typs=C
  242. ErrorResponse
  243. ReadyForQuery
  244. ----
  245. CopyIn {"format":"text","column_formats":["text","text"]}
  246. ErrorResponse {"fields":[{"typ":"C","value":"22P04"}]}
  247. ReadyForQuery {"status":"I"}
  248. # check Sync message is ignored
  249. send
  250. Query {"query": "COPY t FROM STDIN"}
  251. Sync
  252. CopyData "4\t\\N\n"
  253. Sync
  254. Sync
  255. Sync
  256. CopyData "5\t\\N\n"
  257. CopyDone
  258. Query {"query": "SELECT * FROM t ORDER BY i"}
  259. ----
  260. until
  261. ReadyForQuery
  262. ReadyForQuery
  263. ----
  264. CopyIn {"format":"text","column_formats":["text","text"]}
  265. CommandComplete {"tag":"COPY 2"}
  266. ReadyForQuery {"status":"I"}
  267. RowDescription {"fields":[{"name":"i"},{"name":"t"}]}
  268. DataRow {"fields":["1","blah"]}
  269. DataRow {"fields":["2","NULL"]}
  270. DataRow {"fields":["3",""]}
  271. DataRow {"fields":["4","NULL"]}
  272. DataRow {"fields":["5","NULL"]}
  273. CommandComplete {"tag":"SELECT 5"}
  274. ReadyForQuery {"status":"I"}
  275. # ignore junk data after end of copy marker
  276. send
  277. Query {"query": "COPY t FROM STDIN"}
  278. CopyData "\\.\n"
  279. CopyData "invalid data\n"
  280. CopyDone
  281. Query {"query": "SELECT * FROM t ORDER BY i"}
  282. ----
  283. until
  284. ReadyForQuery
  285. ReadyForQuery
  286. ----
  287. CopyIn {"format":"text","column_formats":["text","text"]}
  288. CommandComplete {"tag":"COPY 0"}
  289. ReadyForQuery {"status":"I"}
  290. RowDescription {"fields":[{"name":"i"},{"name":"t"}]}
  291. DataRow {"fields":["1","blah"]}
  292. DataRow {"fields":["2","NULL"]}
  293. DataRow {"fields":["3",""]}
  294. DataRow {"fields":["4","NULL"]}
  295. DataRow {"fields":["5","NULL"]}
  296. CommandComplete {"tag":"SELECT 5"}
  297. ReadyForQuery {"status":"I"}
  298. send
  299. Query {"query": "COPY t FROM STDIN WITH (DELIMITER '||')"}
  300. ----
  301. until
  302. ErrorResponse
  303. ReadyForQuery
  304. ----
  305. ErrorResponse {"fields":[{"typ":"S","value":"ERROR"},{"typ":"C","value":"XX000"},{"typ":"M","value":"COPY delimiter must be a single one-byte character"}]}
  306. ReadyForQuery {"status":"I"}
  307. send
  308. Query {"query": "COPY t FROM STDIN WITH (QUOTE '||')"}
  309. Query {"query": "COPY t FROM STDIN WITH (ESCAPE '||')"}
  310. Query {"query": "COPY t FROM STDIN WITH (HEADER true)"}
  311. ----
  312. until
  313. ErrorResponse
  314. ReadyForQuery
  315. ErrorResponse
  316. ReadyForQuery
  317. ErrorResponse
  318. ReadyForQuery
  319. ----
  320. ErrorResponse {"fields":[{"typ":"S","value":"ERROR"},{"typ":"C","value":"XX000"},{"typ":"M","value":"COPY quote available only in CSV mode"}]}
  321. ReadyForQuery {"status":"I"}
  322. ErrorResponse {"fields":[{"typ":"S","value":"ERROR"},{"typ":"C","value":"XX000"},{"typ":"M","value":"COPY escape available only in CSV mode"}]}
  323. ReadyForQuery {"status":"I"}
  324. ErrorResponse {"fields":[{"typ":"S","value":"ERROR"},{"typ":"C","value":"XX000"},{"typ":"M","value":"COPY HEADER available only in CSV mode"}]}
  325. ReadyForQuery {"status":"I"}