copy-from.pt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. send
  2. Query {"query": "DROP TABLE IF EXISTS a"}
  3. ----
  4. until ignore=NoticeResponse
  5. ReadyForQuery
  6. ----
  7. CommandComplete {"tag":"DROP TABLE"}
  8. ReadyForQuery {"status":"I"}
  9. send
  10. Query {"query": "CREATE TABLE a(a INT, b FLOAT, c TEXT)"}
  11. ----
  12. until
  13. ReadyForQuery
  14. ----
  15. CommandComplete {"tag":"CREATE TABLE"}
  16. ReadyForQuery {"status":"I"}
  17. #
  18. # Invalid data
  19. #
  20. # missing last column
  21. send
  22. Query {"query": "COPY a FROM STDIN"}
  23. ----
  24. until
  25. CopyIn
  26. ----
  27. CopyIn {"format":"text","column_formats":["text","text","text"]}
  28. send
  29. CopyData "1\t2.1"
  30. CopyDone
  31. ----
  32. until err_field_typs=C
  33. ReadyForQuery
  34. ----
  35. ErrorResponse {"fields":[{"typ":"C","value":"22P04"}]}
  36. ReadyForQuery {"status":"I"}
  37. # extra data at the end
  38. send
  39. Query {"query": "COPY a FROM STDIN"}
  40. ----
  41. until
  42. CopyIn
  43. ----
  44. CopyIn {"format":"text","column_formats":["text","text","text"]}
  45. send
  46. CopyData "1\t2.1\ttext\thel"
  47. CopyDone
  48. ----
  49. until
  50. ReadyForQuery
  51. ----
  52. ErrorResponse {"fields":[{"typ":"S","value":"ERROR"},{"typ":"C","value":"22P04"},{"typ":"M","value":"extra data after last expected column"}]}
  53. ReadyForQuery {"status":"I"}
  54. # invalid type
  55. send
  56. Query {"query": "COPY a FROM STDIN"}
  57. ----
  58. until
  59. CopyIn
  60. ----
  61. CopyIn {"format":"text","column_formats":["text","text","text"]}
  62. send
  63. CopyData "text as int\t2.1\ttext\n"
  64. CopyDone
  65. ----
  66. until no_error_fields
  67. ReadyForQuery
  68. ----
  69. ErrorResponse {"fields":[]}
  70. ReadyForQuery {"status":"I"}
  71. # invalid type
  72. send
  73. Query {"query": "COPY a FROM STDIN"}
  74. ----
  75. until
  76. CopyIn
  77. ----
  78. CopyIn {"format":"text","column_formats":["text","text","text"]}
  79. send
  80. CopyData "1\t2.1a\ttext\n"
  81. CopyDone
  82. ----
  83. until no_error_fields
  84. ReadyForQuery
  85. ----
  86. ErrorResponse {"fields":[]}
  87. ReadyForQuery {"status":"I"}
  88. #
  89. # Valid data
  90. #
  91. # send single valid row
  92. send
  93. Query {"query": "COPY a FROM STDIN"}
  94. ----
  95. until
  96. CopyIn
  97. ----
  98. CopyIn {"format":"text","column_formats":["text","text","text"]}
  99. send
  100. CopyData "1\t2.1\ttext\n"
  101. CopyDone
  102. ----
  103. until
  104. ReadyForQuery
  105. ----
  106. CommandComplete {"tag":"COPY 1"}
  107. ReadyForQuery {"status":"I"}
  108. # send multiple valid rows, multiple messages
  109. send
  110. Query {"query": "COPY a FROM STDIN"}
  111. ----
  112. until
  113. CopyIn
  114. ----
  115. CopyIn {"format":"text","column_formats":["text","text","text"]}
  116. send
  117. CopyData "2\t2.1\tsome other text\n"
  118. CopyData "3\t2.1\tlong text\n"
  119. CopyDone
  120. ----
  121. until
  122. ReadyForQuery
  123. ----
  124. CommandComplete {"tag":"COPY 2"}
  125. ReadyForQuery {"status":"I"}
  126. # send multiple valid rows, multiple messages, unaligned data
  127. send
  128. Query {"query": "COPY a FROM STDIN"}
  129. ----
  130. until
  131. CopyIn
  132. ----
  133. CopyIn {"format":"text","column_formats":["text","text","text"]}
  134. send
  135. CopyData "2\t2.1\tsome other text\n4\t3.1\tlong"
  136. CopyData " text "
  137. CopyData "and some more\n"
  138. CopyDone
  139. ----
  140. until
  141. ReadyForQuery
  142. ----
  143. CommandComplete {"tag":"COPY 2"}
  144. ReadyForQuery {"status":"I"}
  145. # send multiple valid rows, single message
  146. send
  147. Query {"query": "COPY a FROM STDIN"}
  148. ----
  149. until
  150. CopyIn
  151. ----
  152. CopyIn {"format":"text","column_formats":["text","text","text"]}
  153. send
  154. CopyData "2\t2.1\tsome other text\n3\t2.1\tlong text\n"
  155. CopyDone
  156. ----
  157. until
  158. ReadyForQuery
  159. ----
  160. CommandComplete {"tag":"COPY 2"}
  161. ReadyForQuery {"status":"I"}
  162. # valid row with no new line at the end
  163. send
  164. Query {"query": "COPY a FROM STDIN"}
  165. ----
  166. until
  167. CopyIn
  168. ----
  169. CopyIn {"format":"text","column_formats":["text","text","text"]}
  170. send
  171. CopyData "5\t5.5\tno new line at the end"
  172. CopyDone
  173. ----
  174. until
  175. ReadyForQuery
  176. ----
  177. CommandComplete {"tag":"COPY 1"}
  178. ReadyForQuery {"status":"I"}
  179. # NULLs
  180. send
  181. Query {"query": "COPY a FROM STDIN"}
  182. ----
  183. until
  184. CopyIn
  185. ----
  186. CopyIn {"format":"text","column_formats":["text","text","text"]}
  187. send
  188. CopyData "\\N\t\\N\t\\N\n"
  189. CopyDone
  190. ----
  191. until
  192. ReadyForQuery
  193. ----
  194. CommandComplete {"tag":"COPY 1"}
  195. ReadyForQuery {"status":"I"}
  196. # supported options: DELIMITER and NULL
  197. send
  198. Query {"query": "COPY a FROM STDIN WITH ( DELIMITER '|', NULL '$' )"}
  199. ----
  200. until
  201. CopyIn
  202. ----
  203. CopyIn {"format":"text","column_formats":["text","text","text"]}
  204. send
  205. CopyData "$|$|row with special delimiter\n"
  206. CopyDone
  207. ----
  208. until
  209. ReadyForQuery
  210. ----
  211. CommandComplete {"tag":"COPY 1"}
  212. ReadyForQuery {"status":"I"}
  213. # dump table
  214. # Our NULL ordering differs from postgres, so do some shennanigans to
  215. # make the results identical between mz and postgres.
  216. send
  217. Query {"query": "COPY (SELECT * FROM a WHERE a IS NOT NULL ORDER BY a, b, c) TO STDOUT"}
  218. Query {"query": "COPY (SELECT * FROM a WHERE a IS NULL AND c IS NOT NULL ORDER BY a, b, c) TO STDOUT"}
  219. Query {"query": "COPY (SELECT * FROM a WHERE c IS NULL ORDER BY a, b, c) TO STDOUT"}
  220. ----
  221. until
  222. ReadyForQuery
  223. ReadyForQuery
  224. ReadyForQuery
  225. ----
  226. CopyOut {"format":"text","column_formats":["text","text","text"]}
  227. CopyData "1\t2.1\ttext\n"
  228. CopyData "2\t2.1\tsome other text\n"
  229. CopyData "2\t2.1\tsome other text\n"
  230. CopyData "2\t2.1\tsome other text\n"
  231. CopyData "3\t2.1\tlong text\n"
  232. CopyData "3\t2.1\tlong text\n"
  233. CopyData "4\t3.1\tlong text and some more\n"
  234. CopyData "5\t5.5\tno new line at the end\n"
  235. CopyDone
  236. CommandComplete {"tag":"COPY 8"}
  237. ReadyForQuery {"status":"I"}
  238. CopyOut {"format":"text","column_formats":["text","text","text"]}
  239. CopyData "\\N\t\\N\trow with special delimiter\n"
  240. CopyDone
  241. CommandComplete {"tag":"COPY 1"}
  242. ReadyForQuery {"status":"I"}
  243. CopyOut {"format":"text","column_formats":["text","text","text"]}
  244. CopyData "\\N\t\\N\t\\N\n"
  245. CopyDone
  246. CommandComplete {"tag":"COPY 1"}
  247. ReadyForQuery {"status":"I"}
  248. # clean up
  249. send
  250. Query {"query": "DROP TABLE a"}
  251. ----
  252. until
  253. ReadyForQuery
  254. ----
  255. CommandComplete {"tag":"DROP TABLE"}
  256. ReadyForQuery {"status":"I"}
  257. # boolean type
  258. send
  259. Query {"query": "DROP TABLE IF EXISTS b"}
  260. ----
  261. until ignore=NoticeResponse
  262. ReadyForQuery
  263. ----
  264. CommandComplete {"tag":"DROP TABLE"}
  265. ReadyForQuery {"status":"I"}
  266. send
  267. Query {"query": "CREATE TABLE b(f1 BOOLEAN)"}
  268. ----
  269. until
  270. ReadyForQuery
  271. ----
  272. CommandComplete {"tag":"CREATE TABLE"}
  273. ReadyForQuery {"status":"I"}
  274. send
  275. Query {"query": "COPY b FROM STDIN"}
  276. ----
  277. until
  278. CopyIn
  279. ----
  280. CopyIn {"format":"text","column_formats":["text"]}
  281. send
  282. CopyData "0\n"
  283. CopyData "1\n"
  284. CopyData "true\n"
  285. CopyData "false\n"
  286. CopyDone
  287. ----
  288. until
  289. ReadyForQuery
  290. ----
  291. CommandComplete {"tag":"COPY 4"}
  292. ReadyForQuery {"status":"I"}
  293. send
  294. Query {"query": "COPY (SELECT * FROM b ORDER BY f1) TO STDOUT"}
  295. ----
  296. until
  297. ReadyForQuery
  298. ----
  299. CopyOut {"format":"text","column_formats":["text"]}
  300. CopyData "f\n"
  301. CopyData "f\n"
  302. CopyData "t\n"
  303. CopyData "t\n"
  304. CopyDone
  305. CommandComplete {"tag":"COPY 4"}
  306. ReadyForQuery {"status":"I"}
  307. send
  308. Query {"query": "DROP TABLE b"}
  309. ----
  310. until
  311. ReadyForQuery
  312. ----
  313. CommandComplete {"tag":"DROP TABLE"}
  314. ReadyForQuery {"status":"I"}
  315. # InF, -InF, NaN
  316. send
  317. Query {"query": "DROP TABLE IF EXISTS inf"}
  318. ----
  319. until ignore=NoticeResponse
  320. ReadyForQuery
  321. ----
  322. CommandComplete {"tag":"DROP TABLE"}
  323. ReadyForQuery {"status":"I"}
  324. send
  325. Query {"query": "CREATE TABLE inf(f1 FLOAT)"}
  326. ----
  327. until
  328. ReadyForQuery
  329. ----
  330. CommandComplete {"tag":"CREATE TABLE"}
  331. ReadyForQuery {"status":"I"}
  332. send
  333. Query {"query": "COPY inf FROM STDIN"}
  334. ----
  335. until
  336. CopyIn
  337. ----
  338. CopyIn {"format":"text","column_formats":["text"]}
  339. send
  340. CopyData "InF\n"
  341. CopyData "-InF\n"
  342. CopyData "NaN\n"
  343. CopyDone
  344. ----
  345. until
  346. ReadyForQuery
  347. ----
  348. CommandComplete {"tag":"COPY 3"}
  349. ReadyForQuery {"status":"I"}
  350. send
  351. Query {"query": "COPY (SELECT * FROM inf ORDER BY f1) TO STDOUT"}
  352. ----
  353. until
  354. ReadyForQuery
  355. ----
  356. CopyOut {"format":"text","column_formats":["text"]}
  357. CopyData "-Infinity\n"
  358. CopyData "Infinity\n"
  359. CopyData "NaN\n"
  360. CopyDone
  361. CommandComplete {"tag":"COPY 3"}
  362. ReadyForQuery {"status":"I"}
  363. send
  364. Query {"query": "DROP TABLE inf"}
  365. ----
  366. until
  367. ReadyForQuery
  368. ----
  369. CommandComplete {"tag":"DROP TABLE"}
  370. ReadyForQuery {"status":"I"}
  371. # timestamps with subsecond precision
  372. send
  373. Query {"query": "DROP TABLE IF EXISTS ts"}
  374. ----
  375. until ignore=NoticeResponse
  376. ReadyForQuery
  377. ----
  378. CommandComplete {"tag":"DROP TABLE"}
  379. ReadyForQuery {"status":"I"}
  380. send
  381. Query {"query": "CREATE TABLE ts(f1 TIMESTAMP)"}
  382. ----
  383. until
  384. ReadyForQuery
  385. ----
  386. CommandComplete {"tag":"CREATE TABLE"}
  387. ReadyForQuery {"status":"I"}
  388. send
  389. Query {"query": "COPY ts FROM STDIN"}
  390. ----
  391. until
  392. CopyIn
  393. ----
  394. CopyIn {"format":"text","column_formats":["text"]}
  395. send
  396. CopyData "2001-02-03 04:05:06.070809\n"
  397. CopyDone
  398. ----
  399. until
  400. ReadyForQuery
  401. ----
  402. CommandComplete {"tag":"COPY 1"}
  403. ReadyForQuery {"status":"I"}
  404. send
  405. Query {"query": "COPY (SELECT * FROM ts) TO STDOUT"}
  406. ----
  407. until
  408. ReadyForQuery
  409. ----
  410. CopyOut {"format":"text","column_formats":["text"]}
  411. CopyData "2001-02-03 04:05:06.070809\n"
  412. CopyDone
  413. CommandComplete {"tag":"COPY 1"}
  414. ReadyForQuery {"status":"I"}
  415. send
  416. Query {"query": "DROP TABLE ts"}
  417. ----
  418. until
  419. ReadyForQuery
  420. ----
  421. CommandComplete {"tag":"DROP TABLE"}
  422. ReadyForQuery {"status":"I"}
  423. #
  424. # NULL check constraint
  425. #
  426. send
  427. Query {"query": "DROP TABLE IF EXISTS not_null_table"}
  428. ----
  429. until ignore=NoticeResponse
  430. ReadyForQuery
  431. ----
  432. CommandComplete {"tag":"DROP TABLE"}
  433. ReadyForQuery {"status":"I"}
  434. send
  435. Query {"query": "CREATE TABLE not_null_table(f1 INT NOT NULL, f2 INT)"}
  436. ----
  437. until
  438. ReadyForQuery
  439. ----
  440. CommandComplete {"tag":"CREATE TABLE"}
  441. ReadyForQuery {"status":"I"}
  442. send
  443. Query {"query": "COPY not_null_table FROM STDIN"}
  444. ----
  445. until
  446. CopyIn
  447. ----
  448. CopyIn {"format":"text","column_formats":["text","text"]}
  449. send
  450. CopyData "1\t2\n"
  451. CopyData "\\N\t\\N\n"
  452. CopyData "3\t4\n"
  453. CopyDone
  454. ----
  455. until no_error_fields
  456. ReadyForQuery
  457. ----
  458. ErrorResponse {"fields":[]}
  459. ReadyForQuery {"status":"I"}
  460. send
  461. Query {"query": "COPY not_null_table(f2) FROM STDIN"}
  462. ----
  463. until
  464. CopyIn
  465. ----
  466. CopyIn {"format":"text","column_formats":["text"]}
  467. send
  468. CopyData "1\n"
  469. CopyDone
  470. ----
  471. until no_error_fields
  472. ReadyForQuery
  473. ----
  474. ErrorResponse {"fields":[]}
  475. ReadyForQuery {"status":"I"}
  476. send
  477. Query {"query": "COPY not_null_table FROM STDIN"}
  478. ----
  479. until
  480. CopyIn
  481. ----
  482. CopyIn {"format":"text","column_formats":["text","text"]}
  483. send
  484. CopyData "1\t\\N\n"
  485. CopyData "2\t3\n"
  486. CopyData "4\t\\N\n"
  487. CopyDone
  488. ----
  489. until
  490. ReadyForQuery
  491. ----
  492. CommandComplete {"tag":"COPY 3"}
  493. ReadyForQuery {"status":"I"}
  494. send
  495. Query {"query": "DROP TABLE not_null_table"}
  496. ----
  497. until
  498. ReadyForQuery
  499. ----
  500. CommandComplete {"tag":"DROP TABLE"}
  501. ReadyForQuery {"status":"I"}
  502. #
  503. # Default value
  504. #
  505. send
  506. Query {"query": "DROP TABLE IF EXISTS default_values"}
  507. ----
  508. until ignore=NoticeResponse
  509. ReadyForQuery
  510. ----
  511. CommandComplete {"tag":"DROP TABLE"}
  512. ReadyForQuery {"status":"I"}
  513. send
  514. Query {"query": "CREATE TABLE default_values(f1 INT NOT NULL DEFAULT 10, f2 INT DEFAULT 20, f3 INT DEFAULT 30)"}
  515. ----
  516. until
  517. ReadyForQuery
  518. ----
  519. CommandComplete {"tag":"CREATE TABLE"}
  520. ReadyForQuery {"status":"I"}
  521. # missing f2; f1 and f3 swapped
  522. send
  523. Query {"query": "COPY default_values(f3, f1) FROM STDIN"}
  524. ----
  525. until
  526. CopyIn
  527. ----
  528. CopyIn {"format":"text","column_formats":["text","text"]}
  529. send
  530. CopyData "\\N\t1\n"
  531. CopyData "3\t11\n"
  532. CopyDone
  533. ----
  534. until
  535. ReadyForQuery
  536. ----
  537. CommandComplete {"tag":"COPY 2"}
  538. ReadyForQuery {"status":"I"}
  539. # missing f1; f2 and f3 swapped
  540. send
  541. Query {"query": "COPY default_values(f3, f2) FROM STDIN"}
  542. ----
  543. until
  544. CopyIn
  545. ----
  546. CopyIn {"format":"text","column_formats":["text","text"]}
  547. send
  548. CopyData "\\N\t2\n"
  549. CopyData "3\t22\n"
  550. CopyDone
  551. ----
  552. until
  553. ReadyForQuery
  554. ----
  555. CommandComplete {"tag":"COPY 2"}
  556. ReadyForQuery {"status":"I"}
  557. # repeated column
  558. send
  559. Query {"query": "COPY default_values(f1, f2, f3, f1) FROM STDIN"}
  560. ----
  561. until no_error_fields
  562. ReadyForQuery
  563. ----
  564. ErrorResponse {"fields":[]}
  565. ReadyForQuery {"status":"I"}
  566. # all columns
  567. send
  568. Query {"query": "COPY default_values(f3, f1, f2) FROM STDIN"}
  569. ----
  570. until
  571. CopyIn
  572. ----
  573. CopyIn {"format":"text","column_formats":["text","text","text"]}
  574. send
  575. CopyData "333\t111\t222\n"
  576. CopyDone
  577. ----
  578. until
  579. ReadyForQuery
  580. ----
  581. CommandComplete {"tag":"COPY 1"}
  582. ReadyForQuery {"status":"I"}
  583. # dump table
  584. send
  585. Query {"query": "COPY (SELECT * FROM default_values ORDER BY f1, f2, f3) TO STDOUT"}
  586. ----
  587. until
  588. ReadyForQuery
  589. ----
  590. CopyOut {"format":"text","column_formats":["text","text","text"]}
  591. CopyData "1\t20\t\\N\n"
  592. CopyData "10\t2\t\\N\n"
  593. CopyData "10\t22\t3\n"
  594. CopyData "11\t20\t3\n"
  595. CopyData "111\t222\t333\n"
  596. CopyDone
  597. CommandComplete {"tag":"COPY 5"}
  598. ReadyForQuery {"status":"I"}
  599. # cleanup
  600. send
  601. Query {"query": "DROP TABLE default_values"}
  602. ----
  603. until
  604. ReadyForQuery
  605. ----
  606. CommandComplete {"tag":"DROP TABLE"}
  607. ReadyForQuery {"status":"I"}