strings.err 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139
  1. Registering pre-existing tables
  2. text_tbl
  3. VARCHAR_TBL
  4. CHAR_TBL
  5. TEXT_TBL
  6. varchar_tbl
  7. <sql-statement>
  8. --
  9. -- STRINGS
  10. -- Test various data entry syntaxes.
  11. --
  12. -- SQL string continuation syntax
  13. -- E021-03 character string literals
  14. SELECT 'first line'
  15. ' - next line'
  16. ' - third line'
  17. AS "Three lines to one";
  18. </sql-statement>
  19. <sql-statement>
  20. -- illegal string continuation syntax
  21. SELECT 'first line'
  22. ' - next line' /* this comment is not allowed here */
  23. ' - third line'
  24. AS "Illegal comment within continuation";
  25. </sql-statement>
  26. -stdin-:<main>: Error: Parse Sql
  27. -stdin-:<main>:4:1: Error: ERROR: syntax error at or near "' - third line'"
  28. ' - third line'
  29. ^
  30. <sql-statement>
  31. -- Unicode escapes
  32. SET standard_conforming_strings TO on;
  33. </sql-statement>
  34. <sql-statement>
  35. SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
  36. </sql-statement>
  37. <sql-statement>
  38. SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*';
  39. </sql-statement>
  40. <sql-statement>
  41. SELECT U&'a\\b' AS "a\b";
  42. </sql-statement>
  43. <sql-statement>
  44. SELECT U&' \' UESCAPE '!' AS "tricky";
  45. </sql-statement>
  46. <sql-statement>
  47. SELECT 'tricky' AS U&"\" UESCAPE '!';
  48. </sql-statement>
  49. <sql-statement>
  50. SELECT U&'wrong: \061';
  51. </sql-statement>
  52. -stdin-:<main>: Error: Parse Sql
  53. -stdin-:<main>:1:19: Error: ERROR: invalid Unicode escape
  54. SELECT U&'wrong: \061';
  55. ^
  56. <sql-statement>
  57. SELECT U&'wrong: \+0061';
  58. </sql-statement>
  59. -stdin-:<main>: Error: Parse Sql
  60. -stdin-:<main>:1:19: Error: ERROR: invalid Unicode escape
  61. SELECT U&'wrong: \+0061';
  62. ^
  63. <sql-statement>
  64. SELECT U&'wrong: +0061' UESCAPE +;
  65. </sql-statement>
  66. -stdin-:<main>: Error: Parse Sql
  67. -stdin-:<main>:1:34: Error: ERROR: UESCAPE must be followed by a simple string literal at or near "+"
  68. SELECT U&'wrong: +0061' UESCAPE +;
  69. ^
  70. <sql-statement>
  71. SELECT U&'wrong: +0061' UESCAPE '+';
  72. </sql-statement>
  73. -stdin-:<main>: Error: Parse Sql
  74. -stdin-:<main>:1:34: Error: ERROR: invalid Unicode escape character at or near "'+'"
  75. SELECT U&'wrong: +0061' UESCAPE '+';
  76. ^
  77. <sql-statement>
  78. SELECT U&'wrong: \db99';
  79. </sql-statement>
  80. -stdin-:<main>: Error: Parse Sql
  81. -stdin-:<main>:1:24: Error: ERROR: invalid Unicode surrogate pair
  82. SELECT U&'wrong: \db99';
  83. ^
  84. <sql-statement>
  85. SELECT U&'wrong: \db99xy';
  86. </sql-statement>
  87. -stdin-:<main>: Error: Parse Sql
  88. -stdin-:<main>:1:24: Error: ERROR: invalid Unicode surrogate pair
  89. SELECT U&'wrong: \db99xy';
  90. ^
  91. <sql-statement>
  92. SELECT U&'wrong: \db99\\';
  93. </sql-statement>
  94. -stdin-:<main>: Error: Parse Sql
  95. -stdin-:<main>:1:24: Error: ERROR: invalid Unicode surrogate pair
  96. SELECT U&'wrong: \db99\\';
  97. ^
  98. <sql-statement>
  99. SELECT U&'wrong: \db99\0061';
  100. </sql-statement>
  101. -stdin-:<main>: Error: Parse Sql
  102. -stdin-:<main>:1:24: Error: ERROR: invalid Unicode surrogate pair
  103. SELECT U&'wrong: \db99\0061';
  104. ^
  105. <sql-statement>
  106. SELECT U&'wrong: \+00db99\+000061';
  107. </sql-statement>
  108. -stdin-:<main>: Error: Parse Sql
  109. -stdin-:<main>:1:27: Error: ERROR: invalid Unicode surrogate pair
  110. SELECT U&'wrong: \+00db99\+000061';
  111. ^
  112. <sql-statement>
  113. SELECT U&'wrong: \+2FFFFF';
  114. </sql-statement>
  115. -stdin-:<main>: Error: Parse Sql
  116. -stdin-:<main>:1:19: Error: ERROR: invalid Unicode escape value
  117. SELECT U&'wrong: \+2FFFFF';
  118. ^
  119. <sql-statement>
  120. -- while we're here, check the same cases in E-style literals
  121. SELECT E'd\u0061t\U00000061' AS "data";
  122. </sql-statement>
  123. <sql-statement>
  124. SELECT E'a\\b' AS "a\b";
  125. </sql-statement>
  126. <sql-statement>
  127. SELECT E'wrong: \u061';
  128. </sql-statement>
  129. -stdin-:<main>: Error: Parse Sql
  130. -stdin-:<main>:1:18: Error: ERROR: invalid Unicode escape
  131. SELECT E'wrong: \u061';
  132. ^
  133. <sql-statement>
  134. SELECT E'wrong: \U0061';
  135. </sql-statement>
  136. -stdin-:<main>: Error: Parse Sql
  137. -stdin-:<main>:1:18: Error: ERROR: invalid Unicode escape
  138. SELECT E'wrong: \U0061';
  139. ^
  140. <sql-statement>
  141. SELECT E'wrong: \udb99';
  142. </sql-statement>
  143. -stdin-:<main>: Error: Parse Sql
  144. -stdin-:<main>:1:24: Error: ERROR: invalid Unicode surrogate pair at or near "'"
  145. SELECT E'wrong: \udb99';
  146. ^
  147. <sql-statement>
  148. SELECT E'wrong: \udb99xy';
  149. </sql-statement>
  150. -stdin-:<main>: Error: Parse Sql
  151. -stdin-:<main>:1:24: Error: ERROR: invalid Unicode surrogate pair at or near "x"
  152. SELECT E'wrong: \udb99xy';
  153. ^
  154. <sql-statement>
  155. SELECT E'wrong: \udb99\\';
  156. </sql-statement>
  157. -stdin-:<main>: Error: Parse Sql
  158. -stdin-:<main>:1:24: Error: ERROR: invalid Unicode surrogate pair at or near "\"
  159. SELECT E'wrong: \udb99\\';
  160. ^
  161. <sql-statement>
  162. SELECT E'wrong: \udb99\u0061';
  163. </sql-statement>
  164. -stdin-:<main>: Error: Parse Sql
  165. -stdin-:<main>:1:24: Error: ERROR: invalid Unicode surrogate pair at or near "\u0061"
  166. SELECT E'wrong: \udb99\u0061';
  167. ^
  168. <sql-statement>
  169. SELECT E'wrong: \U0000db99\U00000061';
  170. </sql-statement>
  171. -stdin-:<main>: Error: Parse Sql
  172. -stdin-:<main>:1:28: Error: ERROR: invalid Unicode surrogate pair at or near "\U00000061"
  173. SELECT E'wrong: \U0000db99\U00000061';
  174. ^
  175. <sql-statement>
  176. SELECT E'wrong: \U002FFFFF';
  177. </sql-statement>
  178. -stdin-:<main>: Error: Parse Sql
  179. -stdin-:<main>:1:18: Error: ERROR: invalid Unicode escape value at or near "\U002FFFFF"
  180. SELECT E'wrong: \U002FFFFF';
  181. ^
  182. <sql-statement>
  183. SET standard_conforming_strings TO off;
  184. </sql-statement>
  185. <sql-statement>
  186. SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
  187. </sql-statement>
  188. <sql-statement>
  189. SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*';
  190. </sql-statement>
  191. <sql-statement>
  192. SELECT U&' \' UESCAPE '!' AS "tricky";
  193. </sql-statement>
  194. <sql-statement>
  195. SELECT 'tricky' AS U&"\" UESCAPE '!';
  196. </sql-statement>
  197. <sql-statement>
  198. SELECT U&'wrong: \061';
  199. </sql-statement>
  200. -stdin-:<main>: Error: Parse Sql
  201. -stdin-:<main>:1:19: Error: ERROR: invalid Unicode escape
  202. SELECT U&'wrong: \061';
  203. ^
  204. <sql-statement>
  205. SELECT U&'wrong: \+0061';
  206. </sql-statement>
  207. -stdin-:<main>: Error: Parse Sql
  208. -stdin-:<main>:1:19: Error: ERROR: invalid Unicode escape
  209. SELECT U&'wrong: \+0061';
  210. ^
  211. <sql-statement>
  212. SELECT U&'wrong: +0061' UESCAPE '+';
  213. </sql-statement>
  214. -stdin-:<main>: Error: Parse Sql
  215. -stdin-:<main>:1:34: Error: ERROR: invalid Unicode escape character at or near "'+'"
  216. SELECT U&'wrong: +0061' UESCAPE '+';
  217. ^
  218. <sql-statement>
  219. RESET standard_conforming_strings;
  220. </sql-statement>
  221. <sql-statement>
  222. -- bytea
  223. SET bytea_output TO hex;
  224. </sql-statement>
  225. <sql-statement>
  226. SELECT E'\\xDeAdBeEf'::bytea;
  227. </sql-statement>
  228. <sql-statement>
  229. SELECT E'\\x De Ad Be Ef '::bytea;
  230. </sql-statement>
  231. <sql-statement>
  232. SELECT E'\\xDeAdBeE'::bytea;
  233. </sql-statement>
  234. -stdin-:<main>: Fatal: Execution
  235. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  236. SELECT E'\\xDeAdBeE'::bytea;
  237. ^
  238. -stdin-:<main>:1:1: Fatal: ERROR: invalid hexadecimal data: odd number of digits
  239. SELECT E'\\xDeAdBeE'::bytea;
  240. ^
  241. <sql-statement>
  242. SELECT E'\\xDeAdBeEx'::bytea;
  243. </sql-statement>
  244. -stdin-:<main>: Fatal: Execution
  245. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  246. SELECT E'\\xDeAdBeEx'::bytea;
  247. ^
  248. -stdin-:<main>:1:1: Fatal: ERROR: invalid hexadecimal digit: "x"
  249. SELECT E'\\xDeAdBeEx'::bytea;
  250. ^
  251. <sql-statement>
  252. SELECT E'\\xDe00BeEf'::bytea;
  253. </sql-statement>
  254. <sql-statement>
  255. SELECT E'DeAdBeEf'::bytea;
  256. </sql-statement>
  257. <sql-statement>
  258. SELECT E'De\\000dBeEf'::bytea;
  259. </sql-statement>
  260. <sql-statement>
  261. SELECT E'De\123dBeEf'::bytea;
  262. </sql-statement>
  263. <sql-statement>
  264. SELECT E'De\\123dBeEf'::bytea;
  265. </sql-statement>
  266. <sql-statement>
  267. SELECT E'De\\678dBeEf'::bytea;
  268. </sql-statement>
  269. -stdin-:<main>: Fatal: Execution
  270. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  271. SELECT E'De\\678dBeEf'::bytea;
  272. ^
  273. -stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type bytea
  274. SELECT E'De\\678dBeEf'::bytea;
  275. ^
  276. <sql-statement>
  277. SET bytea_output TO escape;
  278. </sql-statement>
  279. <sql-statement>
  280. SELECT E'\\xDeAdBeEf'::bytea;
  281. </sql-statement>
  282. <sql-statement>
  283. SELECT E'\\x De Ad Be Ef '::bytea;
  284. </sql-statement>
  285. <sql-statement>
  286. SELECT E'\\xDe00BeEf'::bytea;
  287. </sql-statement>
  288. <sql-statement>
  289. SELECT E'DeAdBeEf'::bytea;
  290. </sql-statement>
  291. <sql-statement>
  292. SELECT E'De\\000dBeEf'::bytea;
  293. </sql-statement>
  294. <sql-statement>
  295. SELECT E'De\\123dBeEf'::bytea;
  296. </sql-statement>
  297. <sql-statement>
  298. --
  299. -- test conversions between various string types
  300. -- E021-10 implicit casting among the character data types
  301. --
  302. SELECT CAST(f1 AS text) AS "text(char)" FROM CHAR_TBL;
  303. </sql-statement>
  304. <sql-statement>
  305. SELECT CAST(f1 AS text) AS "text(varchar)" FROM VARCHAR_TBL;
  306. </sql-statement>
  307. <sql-statement>
  308. SELECT CAST(name 'namefield' AS text) AS "text(name)";
  309. </sql-statement>
  310. <sql-statement>
  311. -- since this is an explicit cast, it should truncate w/o error:
  312. SELECT CAST(f1 AS char(10)) AS "char(text)" FROM TEXT_TBL;
  313. </sql-statement>
  314. <sql-statement>
  315. -- note: implicit-cast case is tested in char.sql
  316. SELECT CAST(f1 AS char(20)) AS "char(text)" FROM TEXT_TBL;
  317. </sql-statement>
  318. <sql-statement>
  319. SELECT CAST(f1 AS char(10)) AS "char(varchar)" FROM VARCHAR_TBL;
  320. </sql-statement>
  321. <sql-statement>
  322. SELECT CAST(name 'namefield' AS char(10)) AS "char(name)";
  323. </sql-statement>
  324. <sql-statement>
  325. SELECT CAST(f1 AS varchar) AS "varchar(text)" FROM TEXT_TBL;
  326. </sql-statement>
  327. <sql-statement>
  328. SELECT CAST(f1 AS varchar) AS "varchar(char)" FROM CHAR_TBL;
  329. </sql-statement>
  330. <sql-statement>
  331. SELECT CAST(name 'namefield' AS varchar) AS "varchar(name)";
  332. </sql-statement>
  333. <sql-statement>
  334. --
  335. -- test SQL string functions
  336. -- E### and T### are feature reference numbers from SQL99
  337. --
  338. -- E021-09 trim function
  339. SELECT TRIM(BOTH FROM ' bunch o blanks ') = 'bunch o blanks' AS "bunch o blanks";
  340. </sql-statement>
  341. <sql-statement>
  342. SELECT TRIM(LEADING FROM ' bunch o blanks ') = 'bunch o blanks ' AS "bunch o blanks ";
  343. </sql-statement>
  344. <sql-statement>
  345. SELECT TRIM(TRAILING FROM ' bunch o blanks ') = ' bunch o blanks' AS " bunch o blanks";
  346. </sql-statement>
  347. <sql-statement>
  348. SELECT TRIM(BOTH 'x' FROM 'xxxxxsome Xsxxxxx') = 'some Xs' AS "some Xs";
  349. </sql-statement>
  350. <sql-statement>
  351. -- E021-06 substring expression
  352. SELECT SUBSTRING('1234567890' FROM 3) = '34567890' AS "34567890";
  353. </sql-statement>
  354. <sql-statement>
  355. SELECT SUBSTRING('1234567890' FROM 4 FOR 3) = '456' AS "456";
  356. </sql-statement>
  357. <sql-statement>
  358. -- test overflow cases
  359. SELECT SUBSTRING('string' FROM 2 FOR 2147483646) AS "tring";
  360. </sql-statement>
  361. <sql-statement>
  362. SELECT SUBSTRING('string' FROM -10 FOR 2147483646) AS "string";
  363. </sql-statement>
  364. <sql-statement>
  365. SELECT SUBSTRING('string' FROM -10 FOR -2147483646) AS "error";
  366. </sql-statement>
  367. -stdin-:<main>: Fatal: Execution
  368. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  369. SELECT SUBSTRING('string' FROM -10 FOR -2147483646) AS "error";
  370. ^
  371. -stdin-:<main>:1:1: Fatal: ERROR: negative substring length not allowed
  372. SELECT SUBSTRING('string' FROM -10 FOR -2147483646) AS "error";
  373. ^
  374. <sql-statement>
  375. -- T581 regular expression substring (with SQL's bizarre regexp syntax)
  376. SELECT SUBSTRING('abcdefg' SIMILAR 'a#"(b_d)#"%' ESCAPE '#') AS "bcd";
  377. </sql-statement>
  378. -stdin-:<main>: Fatal: Execution
  379. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  380. -- T581 regular expression substring (with SQL's bizarre regexp syntax)
  381. ^
  382. -stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "a#"(b_d)#"%"
  383. -- T581 regular expression substring (with SQL's bizarre regexp syntax)
  384. ^
  385. <sql-statement>
  386. -- obsolete SQL99 syntax
  387. SELECT SUBSTRING('abcdefg' FROM 'a#"(b_d)#"%' FOR '#') AS "bcd";
  388. </sql-statement>
  389. -stdin-:<main>: Fatal: Execution
  390. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  391. -- obsolete SQL99 syntax
  392. ^
  393. -stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "a#"(b_d)#"%"
  394. -- obsolete SQL99 syntax
  395. ^
  396. <sql-statement>
  397. -- No match should return NULL
  398. SELECT SUBSTRING('abcdefg' SIMILAR '#"(b_d)#"%' ESCAPE '#') IS NULL AS "True";
  399. </sql-statement>
  400. -stdin-:<main>: Fatal: Execution
  401. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  402. -- No match should return NULL
  403. ^
  404. -stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "#"(b_d)#"%"
  405. -- No match should return NULL
  406. ^
  407. <sql-statement>
  408. -- Null inputs should return NULL
  409. SELECT SUBSTRING('abcdefg' SIMILAR '%' ESCAPE NULL) IS NULL AS "True";
  410. </sql-statement>
  411. -stdin-:<main>: Fatal: Execution
  412. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  413. -- Null inputs should return NULL
  414. ^
  415. -stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "%"
  416. -- Null inputs should return NULL
  417. ^
  418. <sql-statement>
  419. SELECT SUBSTRING(NULL SIMILAR '%' ESCAPE '#') IS NULL AS "True";
  420. </sql-statement>
  421. <sql-statement>
  422. SELECT SUBSTRING('abcdefg' SIMILAR NULL ESCAPE '#') IS NULL AS "True";
  423. </sql-statement>
  424. <sql-statement>
  425. -- The first and last parts should act non-greedy
  426. SELECT SUBSTRING('abcdefg' SIMILAR 'a#"%#"g' ESCAPE '#') AS "bcdef";
  427. </sql-statement>
  428. -stdin-:<main>: Fatal: Execution
  429. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  430. -- The first and last parts should act non-greedy
  431. ^
  432. -stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "a#"%#"g"
  433. -- The first and last parts should act non-greedy
  434. ^
  435. <sql-statement>
  436. SELECT SUBSTRING('abcdefg' SIMILAR 'a*#"%#"g*' ESCAPE '#') AS "abcdefg";
  437. </sql-statement>
  438. -stdin-:<main>: Fatal: Execution
  439. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  440. SELECT SUBSTRING('abcdefg' SIMILAR 'a*#"%#"g*' ESCAPE '#') AS "abcdefg";
  441. ^
  442. -stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "a*#"%#"g*"
  443. SELECT SUBSTRING('abcdefg' SIMILAR 'a*#"%#"g*' ESCAPE '#') AS "abcdefg";
  444. ^
  445. <sql-statement>
  446. -- Vertical bar in any part affects only that part
  447. SELECT SUBSTRING('abcdefg' SIMILAR 'a|b#"%#"g' ESCAPE '#') AS "bcdef";
  448. </sql-statement>
  449. -stdin-:<main>: Fatal: Execution
  450. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  451. -- Vertical bar in any part affects only that part
  452. ^
  453. -stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "a|b#"%#"g"
  454. -- Vertical bar in any part affects only that part
  455. ^
  456. <sql-statement>
  457. SELECT SUBSTRING('abcdefg' SIMILAR 'a#"%#"x|g' ESCAPE '#') AS "bcdef";
  458. </sql-statement>
  459. -stdin-:<main>: Fatal: Execution
  460. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  461. SELECT SUBSTRING('abcdefg' SIMILAR 'a#"%#"x|g' ESCAPE '#') AS "bcdef";
  462. ^
  463. -stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "a#"%#"x|g"
  464. SELECT SUBSTRING('abcdefg' SIMILAR 'a#"%#"x|g' ESCAPE '#') AS "bcdef";
  465. ^
  466. <sql-statement>
  467. SELECT SUBSTRING('abcdefg' SIMILAR 'a#"%|ab#"g' ESCAPE '#') AS "bcdef";
  468. </sql-statement>
  469. -stdin-:<main>: Fatal: Execution
  470. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  471. SELECT SUBSTRING('abcdefg' SIMILAR 'a#"%|ab#"g' ESCAPE '#') AS "bcdef";
  472. ^
  473. -stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "a#"%|ab#"g"
  474. SELECT SUBSTRING('abcdefg' SIMILAR 'a#"%|ab#"g' ESCAPE '#') AS "bcdef";
  475. ^
  476. <sql-statement>
  477. -- Can't have more than two part separators
  478. SELECT SUBSTRING('abcdefg' SIMILAR 'a*#"%#"g*#"x' ESCAPE '#') AS "error";
  479. </sql-statement>
  480. -stdin-:<main>: Fatal: Execution
  481. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  482. -- Can't have more than two part separators
  483. ^
  484. -stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "a*#"%#"g*#"x"
  485. -- Can't have more than two part separators
  486. ^
  487. <sql-statement>
  488. -- Postgres extension: with 0 or 1 separator, assume parts 1 and 3 are empty
  489. SELECT SUBSTRING('abcdefg' SIMILAR 'a#"%g' ESCAPE '#') AS "bcdefg";
  490. </sql-statement>
  491. -stdin-:<main>: Fatal: Execution
  492. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  493. -- Postgres extension: with 0 or 1 separator, assume parts 1 and 3 are empty
  494. ^
  495. -stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "a#"%g"
  496. -- Postgres extension: with 0 or 1 separator, assume parts 1 and 3 are empty
  497. ^
  498. <sql-statement>
  499. SELECT SUBSTRING('abcdefg' SIMILAR 'a%g' ESCAPE '#') AS "abcdefg";
  500. </sql-statement>
  501. -stdin-:<main>: Fatal: Execution
  502. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  503. SELECT SUBSTRING('abcdefg' SIMILAR 'a%g' ESCAPE '#') AS "abcdefg";
  504. ^
  505. -stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "a%g"
  506. SELECT SUBSTRING('abcdefg' SIMILAR 'a%g' ESCAPE '#') AS "abcdefg";
  507. ^
  508. <sql-statement>
  509. -- substring() with just two arguments is not allowed by SQL spec;
  510. -- we accept it, but we interpret the pattern as a POSIX regexp not SQL
  511. SELECT SUBSTRING('abcdefg' FROM 'c.e') AS "cde";
  512. </sql-statement>
  513. <sql-statement>
  514. -- With a parenthesized subexpression, return only what matches the subexpr
  515. SELECT SUBSTRING('abcdefg' FROM 'b(.*)f') AS "cde";
  516. </sql-statement>
  517. <sql-statement>
  518. -- Check behavior of SIMILAR TO, which uses largely the same regexp variant
  519. SELECT 'abcdefg' SIMILAR TO '_bcd%' AS true;
  520. </sql-statement>
  521. -stdin-:<main>: Error: Parse Sql
  522. -stdin-:<main>:2:18: Error: A_Expr_Kind unsupported value: 9
  523. SELECT 'abcdefg' SIMILAR TO '_bcd%' AS true;
  524. ^
  525. <sql-statement>
  526. SELECT 'abcdefg' SIMILAR TO 'bcd%' AS false;
  527. </sql-statement>
  528. -stdin-:<main>: Error: Parse Sql
  529. -stdin-:<main>:1:18: Error: A_Expr_Kind unsupported value: 9
  530. SELECT 'abcdefg' SIMILAR TO 'bcd%' AS false;
  531. ^
  532. <sql-statement>
  533. SELECT 'abcdefg' SIMILAR TO '_bcd#%' ESCAPE '#' AS false;
  534. </sql-statement>
  535. -stdin-:<main>: Error: Parse Sql
  536. -stdin-:<main>:1:18: Error: A_Expr_Kind unsupported value: 9
  537. SELECT 'abcdefg' SIMILAR TO '_bcd#%' ESCAPE '#' AS false;
  538. ^
  539. <sql-statement>
  540. SELECT 'abcd%' SIMILAR TO '_bcd#%' ESCAPE '#' AS true;
  541. </sql-statement>
  542. -stdin-:<main>: Error: Parse Sql
  543. -stdin-:<main>:1:16: Error: A_Expr_Kind unsupported value: 9
  544. SELECT 'abcd%' SIMILAR TO '_bcd#%' ESCAPE '#' AS true;
  545. ^
  546. <sql-statement>
  547. -- Postgres uses '\' as the default escape character, which is not per spec
  548. SELECT 'abcdefg' SIMILAR TO '_bcd\%' AS false;
  549. </sql-statement>
  550. -stdin-:<main>: Error: Parse Sql
  551. -stdin-:<main>:2:18: Error: A_Expr_Kind unsupported value: 9
  552. SELECT 'abcdefg' SIMILAR TO '_bcd\%' AS false;
  553. ^
  554. <sql-statement>
  555. -- and an empty string to mean "no escape", which is also not per spec
  556. SELECT 'abcd\efg' SIMILAR TO '_bcd\%' ESCAPE '' AS true;
  557. </sql-statement>
  558. -stdin-:<main>: Error: Parse Sql
  559. -stdin-:<main>:2:19: Error: A_Expr_Kind unsupported value: 9
  560. SELECT 'abcd\efg' SIMILAR TO '_bcd\%' ESCAPE '' AS true;
  561. ^
  562. <sql-statement>
  563. -- these behaviors are per spec, though:
  564. SELECT 'abcdefg' SIMILAR TO '_bcd%' ESCAPE NULL AS null;
  565. </sql-statement>
  566. -stdin-:<main>: Error: Parse Sql
  567. -stdin-:<main>:2:18: Error: A_Expr_Kind unsupported value: 9
  568. SELECT 'abcdefg' SIMILAR TO '_bcd%' ESCAPE NULL AS null;
  569. ^
  570. <sql-statement>
  571. SELECT 'abcdefg' SIMILAR TO '_bcd#%' ESCAPE '##' AS error;
  572. </sql-statement>
  573. -stdin-:<main>: Error: Parse Sql
  574. -stdin-:<main>:1:18: Error: A_Expr_Kind unsupported value: 9
  575. SELECT 'abcdefg' SIMILAR TO '_bcd#%' ESCAPE '##' AS error;
  576. ^
  577. <sql-statement>
  578. -- Test back reference in regexp_replace
  579. SELECT regexp_replace('1112223333', E'(\\d{3})(\\d{3})(\\d{4})', E'(\\1) \\2-\\3');
  580. </sql-statement>
  581. <sql-statement>
  582. SELECT regexp_replace('AAA BBB CCC ', E'\\s+', ' ', 'g');
  583. </sql-statement>
  584. <sql-statement>
  585. SELECT regexp_replace('AAA', '^|$', 'Z', 'g');
  586. </sql-statement>
  587. <sql-statement>
  588. SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'gi');
  589. </sql-statement>
  590. <sql-statement>
  591. -- invalid regexp option
  592. SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'z');
  593. </sql-statement>
  594. -stdin-:<main>: Fatal: Execution
  595. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  596. -- invalid regexp option
  597. ^
  598. -stdin-:<main>:1:1: Fatal: ERROR: invalid regular expression option: "z"
  599. -- invalid regexp option
  600. ^
  601. <sql-statement>
  602. -- set so we can tell NULL from empty string
  603. \pset null '\\N'
  604. </sql-statement>
  605. <sql-statement>
  606. -- return all matches from regexp
  607. SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$);
  608. </sql-statement>
  609. -stdin-:<main>: Error: Parse Sql
  610. -stdin-:<main>:2:8: Error: Generator functions are not allowed in: SELECT
  611. SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$);
  612. ^
  613. <sql-statement>
  614. -- test case insensitive
  615. SELECT regexp_matches('foObARbEqUEbAz', $re$(bar)(beque)$re$, 'i');
  616. </sql-statement>
  617. -stdin-:<main>: Error: Parse Sql
  618. -stdin-:<main>:2:8: Error: Generator functions are not allowed in: SELECT
  619. SELECT regexp_matches('foObARbEqUEbAz', $re$(bar)(beque)$re$, 'i');
  620. ^
  621. <sql-statement>
  622. -- global option - more than one match
  623. SELECT regexp_matches('foobarbequebazilbarfbonk', $re$(b[^b]+)(b[^b]+)$re$, 'g');
  624. </sql-statement>
  625. -stdin-:<main>: Error: Parse Sql
  626. -stdin-:<main>:2:8: Error: Generator functions are not allowed in: SELECT
  627. SELECT regexp_matches('foobarbequebazilbarfbonk', $re$(b[^b]+)(b[^b]+)$re$, 'g');
  628. ^
  629. <sql-statement>
  630. -- empty capture group (matched empty string)
  631. SELECT regexp_matches('foobarbequebaz', $re$(bar)(.*)(beque)$re$);
  632. </sql-statement>
  633. -stdin-:<main>: Error: Parse Sql
  634. -stdin-:<main>:2:8: Error: Generator functions are not allowed in: SELECT
  635. SELECT regexp_matches('foobarbequebaz', $re$(bar)(.*)(beque)$re$);
  636. ^
  637. <sql-statement>
  638. -- no match
  639. SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)(beque)$re$);
  640. </sql-statement>
  641. -stdin-:<main>: Error: Parse Sql
  642. -stdin-:<main>:2:8: Error: Generator functions are not allowed in: SELECT
  643. SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)(beque)$re$);
  644. ^
  645. <sql-statement>
  646. -- optional capture group did not match, null entry in array
  647. SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)?(beque)$re$);
  648. </sql-statement>
  649. -stdin-:<main>: Error: Parse Sql
  650. -stdin-:<main>:2:8: Error: Generator functions are not allowed in: SELECT
  651. SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)?(beque)$re$);
  652. ^
  653. <sql-statement>
  654. -- no capture groups
  655. SELECT regexp_matches('foobarbequebaz', $re$barbeque$re$);
  656. </sql-statement>
  657. -stdin-:<main>: Error: Parse Sql
  658. -stdin-:<main>:2:8: Error: Generator functions are not allowed in: SELECT
  659. SELECT regexp_matches('foobarbequebaz', $re$barbeque$re$);
  660. ^
  661. <sql-statement>
  662. -- start/end-of-line matches are of zero length
  663. SELECT regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '^', 'mg');
  664. </sql-statement>
  665. -stdin-:<main>: Error: Parse Sql
  666. -stdin-:<main>:2:8: Error: Generator functions are not allowed in: SELECT
  667. SELECT regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '^', 'mg');
  668. ^
  669. <sql-statement>
  670. SELECT regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '$', 'mg');
  671. </sql-statement>
  672. -stdin-:<main>: Error: Parse Sql
  673. -stdin-:<main>:1:8: Error: Generator functions are not allowed in: SELECT
  674. SELECT regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '$', 'mg');
  675. ^
  676. <sql-statement>
  677. SELECT regexp_matches('1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '^.?', 'mg');
  678. </sql-statement>
  679. -stdin-:<main>: Error: Parse Sql
  680. -stdin-:<main>:1:8: Error: Generator functions are not allowed in: SELECT
  681. SELECT regexp_matches('1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '^.?', 'mg');
  682. ^
  683. <sql-statement>
  684. SELECT regexp_matches(chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '.?$', 'mg');
  685. </sql-statement>
  686. -stdin-:<main>: Error: Parse Sql
  687. -stdin-:<main>:1:8: Error: Generator functions are not allowed in: SELECT
  688. SELECT regexp_matches(chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '.?$', 'mg');
  689. ^
  690. <sql-statement>
  691. SELECT regexp_matches(chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4', '.?$', 'mg');
  692. </sql-statement>
  693. -stdin-:<main>: Error: Parse Sql
  694. -stdin-:<main>:1:8: Error: Generator functions are not allowed in: SELECT
  695. SELECT regexp_matches(chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4', '.?$', 'mg');
  696. ^
  697. <sql-statement>
  698. -- give me errors
  699. SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$, 'gz');
  700. </sql-statement>
  701. -stdin-:<main>: Error: Parse Sql
  702. -stdin-:<main>:2:8: Error: Generator functions are not allowed in: SELECT
  703. SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$, 'gz');
  704. ^
  705. <sql-statement>
  706. SELECT regexp_matches('foobarbequebaz', $re$(barbeque$re$);
  707. </sql-statement>
  708. -stdin-:<main>: Error: Parse Sql
  709. -stdin-:<main>:1:8: Error: Generator functions are not allowed in: SELECT
  710. SELECT regexp_matches('foobarbequebaz', $re$(barbeque$re$);
  711. ^
  712. <sql-statement>
  713. SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque){2,1}$re$);
  714. </sql-statement>
  715. -stdin-:<main>: Error: Parse Sql
  716. -stdin-:<main>:1:8: Error: Generator functions are not allowed in: SELECT
  717. SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque){2,1}$re$);
  718. ^
  719. <sql-statement>
  720. -- split string on regexp
  721. SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', $re$\s+$re$) AS foo;
  722. </sql-statement>
  723. <sql-statement>
  724. SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', $re$\s+$re$);
  725. </sql-statement>
  726. <sql-statement>
  727. SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', $re$\s*$re$) AS foo;
  728. </sql-statement>
  729. <sql-statement>
  730. SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', $re$\s*$re$);
  731. </sql-statement>
  732. <sql-statement>
  733. SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', '') AS foo;
  734. </sql-statement>
  735. <sql-statement>
  736. SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', '');
  737. </sql-statement>
  738. <sql-statement>
  739. -- case insensitive
  740. SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'i') AS foo;
  741. </sql-statement>
  742. <sql-statement>
  743. SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'i');
  744. </sql-statement>
  745. <sql-statement>
  746. -- no match of pattern
  747. SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', 'nomatch') AS foo;
  748. </sql-statement>
  749. <sql-statement>
  750. SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', 'nomatch');
  751. </sql-statement>
  752. <sql-statement>
  753. -- some corner cases
  754. SELECT regexp_split_to_array('123456','1');
  755. </sql-statement>
  756. <sql-statement>
  757. SELECT regexp_split_to_array('123456','6');
  758. </sql-statement>
  759. <sql-statement>
  760. SELECT regexp_split_to_array('123456','.');
  761. </sql-statement>
  762. <sql-statement>
  763. SELECT regexp_split_to_array('123456','');
  764. </sql-statement>
  765. <sql-statement>
  766. SELECT regexp_split_to_array('123456','(?:)');
  767. </sql-statement>
  768. <sql-statement>
  769. SELECT regexp_split_to_array('1','');
  770. </sql-statement>
  771. <sql-statement>
  772. -- errors
  773. SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'zippy') AS foo;
  774. </sql-statement>
  775. -stdin-:<main>: Fatal: Execution
  776. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  777. -- errors
  778. ^
  779. -stdin-:<main>:1:1: Fatal: ERROR: invalid regular expression option: "z"
  780. -- errors
  781. ^
  782. <sql-statement>
  783. SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'iz');
  784. </sql-statement>
  785. -stdin-:<main>: Fatal: Execution
  786. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  787. SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'iz');
  788. ^
  789. -stdin-:<main>:1:1: Fatal: ERROR: invalid regular expression option: "z"
  790. SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'iz');
  791. ^
  792. <sql-statement>
  793. -- global option meaningless for regexp_split
  794. SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'g') AS foo;
  795. </sql-statement>
  796. -stdin-:<main>: Fatal: Execution
  797. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  798. -- global option meaningless for regexp_split
  799. ^
  800. -stdin-:<main>:1:1: Fatal: ERROR: regexp_split_to_table() does not support the "global" option
  801. -- global option meaningless for regexp_split
  802. ^
  803. <sql-statement>
  804. SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'g');
  805. </sql-statement>
  806. -stdin-:<main>: Fatal: Execution
  807. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  808. SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'g');
  809. ^
  810. -stdin-:<main>:1:1: Fatal: ERROR: regexp_split_to_array() does not support the "global" option
  811. SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'g');
  812. ^
  813. <sql-statement>
  814. -- change NULL-display back
  815. \pset null ''
  816. </sql-statement>
  817. <sql-statement>
  818. -- E021-11 position expression
  819. SELECT POSITION('4' IN '1234567890') = '4' AS "4";
  820. </sql-statement>
  821. <sql-statement>
  822. SELECT POSITION('5' IN '1234567890') = '5' AS "5";
  823. </sql-statement>
  824. <sql-statement>
  825. -- T312 character overlay function
  826. SELECT OVERLAY('abcdef' PLACING '45' FROM 4) AS "abc45f";
  827. </sql-statement>
  828. <sql-statement>
  829. SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5) AS "yabadaba";
  830. </sql-statement>
  831. <sql-statement>
  832. SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5 FOR 0) AS "yabadabadoo";
  833. </sql-statement>
  834. <sql-statement>
  835. SELECT OVERLAY('babosa' PLACING 'ubb' FROM 2 FOR 4) AS "bubba";
  836. </sql-statement>
  837. <sql-statement>
  838. --
  839. -- test LIKE
  840. -- Be sure to form every test as a LIKE/NOT LIKE pair.
  841. --
  842. -- simplest examples
  843. -- E061-04 like predicate
  844. SELECT 'hawkeye' LIKE 'h%' AS "true";
  845. </sql-statement>
  846. <sql-statement>
  847. SELECT 'hawkeye' NOT LIKE 'h%' AS "false";
  848. </sql-statement>
  849. <sql-statement>
  850. SELECT 'hawkeye' LIKE 'H%' AS "false";
  851. </sql-statement>
  852. <sql-statement>
  853. SELECT 'hawkeye' NOT LIKE 'H%' AS "true";
  854. </sql-statement>
  855. <sql-statement>
  856. SELECT 'hawkeye' LIKE 'indio%' AS "false";
  857. </sql-statement>
  858. <sql-statement>
  859. SELECT 'hawkeye' NOT LIKE 'indio%' AS "true";
  860. </sql-statement>
  861. <sql-statement>
  862. SELECT 'hawkeye' LIKE 'h%eye' AS "true";
  863. </sql-statement>
  864. <sql-statement>
  865. SELECT 'hawkeye' NOT LIKE 'h%eye' AS "false";
  866. </sql-statement>
  867. <sql-statement>
  868. SELECT 'indio' LIKE '_ndio' AS "true";
  869. </sql-statement>
  870. <sql-statement>
  871. SELECT 'indio' NOT LIKE '_ndio' AS "false";
  872. </sql-statement>
  873. <sql-statement>
  874. SELECT 'indio' LIKE 'in__o' AS "true";
  875. </sql-statement>
  876. <sql-statement>
  877. SELECT 'indio' NOT LIKE 'in__o' AS "false";
  878. </sql-statement>
  879. <sql-statement>
  880. SELECT 'indio' LIKE 'in_o' AS "false";
  881. </sql-statement>
  882. <sql-statement>
  883. SELECT 'indio' NOT LIKE 'in_o' AS "true";
  884. </sql-statement>
  885. <sql-statement>
  886. SELECT 'abc'::name LIKE '_b_' AS "true";
  887. </sql-statement>
  888. <sql-statement>
  889. SELECT 'abc'::name NOT LIKE '_b_' AS "false";
  890. </sql-statement>
  891. <sql-statement>
  892. SELECT 'abc'::bytea LIKE '_b_'::bytea AS "true";
  893. </sql-statement>
  894. -stdin-:<main>: Error: Type annotation
  895. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
  896. SELECT 'abc'::bytea LIKE '_b_'::bytea AS "true";
  897. ^
  898. -stdin-:<main>:1:21: Error: At function: PgLike
  899. SELECT 'abc'::bytea LIKE '_b_'::bytea AS "true";
  900. ^
  901. -stdin-:<main>:1:21: Error: Expected pg text, but got bytea
  902. SELECT 'abc'::bytea LIKE '_b_'::bytea AS "true";
  903. ^
  904. <sql-statement>
  905. SELECT 'abc'::bytea NOT LIKE '_b_'::bytea AS "false";
  906. </sql-statement>
  907. -stdin-:<main>: Error: Type annotation
  908. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
  909. SELECT 'abc'::bytea NOT LIKE '_b_'::bytea AS "false";
  910. ^
  911. -stdin-:<main>:1:21: Error: At function: PgNot, At function: PgLike
  912. SELECT 'abc'::bytea NOT LIKE '_b_'::bytea AS "false";
  913. ^
  914. -stdin-:<main>:1:21: Error: Expected pg text, but got bytea
  915. SELECT 'abc'::bytea NOT LIKE '_b_'::bytea AS "false";
  916. ^
  917. <sql-statement>
  918. -- unused escape character
  919. SELECT 'hawkeye' LIKE 'h%' ESCAPE '#' AS "true";
  920. </sql-statement>
  921. <sql-statement>
  922. SELECT 'hawkeye' NOT LIKE 'h%' ESCAPE '#' AS "false";
  923. </sql-statement>
  924. <sql-statement>
  925. SELECT 'indio' LIKE 'ind_o' ESCAPE '$' AS "true";
  926. </sql-statement>
  927. <sql-statement>
  928. SELECT 'indio' NOT LIKE 'ind_o' ESCAPE '$' AS "false";
  929. </sql-statement>
  930. <sql-statement>
  931. -- escape character
  932. -- E061-05 like predicate with escape clause
  933. SELECT 'h%' LIKE 'h#%' ESCAPE '#' AS "true";
  934. </sql-statement>
  935. <sql-statement>
  936. SELECT 'h%' NOT LIKE 'h#%' ESCAPE '#' AS "false";
  937. </sql-statement>
  938. <sql-statement>
  939. SELECT 'h%wkeye' LIKE 'h#%' ESCAPE '#' AS "false";
  940. </sql-statement>
  941. <sql-statement>
  942. SELECT 'h%wkeye' NOT LIKE 'h#%' ESCAPE '#' AS "true";
  943. </sql-statement>
  944. <sql-statement>
  945. SELECT 'h%wkeye' LIKE 'h#%%' ESCAPE '#' AS "true";
  946. </sql-statement>
  947. <sql-statement>
  948. SELECT 'h%wkeye' NOT LIKE 'h#%%' ESCAPE '#' AS "false";
  949. </sql-statement>
  950. <sql-statement>
  951. SELECT 'h%awkeye' LIKE 'h#%a%k%e' ESCAPE '#' AS "true";
  952. </sql-statement>
  953. <sql-statement>
  954. SELECT 'h%awkeye' NOT LIKE 'h#%a%k%e' ESCAPE '#' AS "false";
  955. </sql-statement>
  956. <sql-statement>
  957. SELECT 'indio' LIKE '_ndio' ESCAPE '$' AS "true";
  958. </sql-statement>
  959. <sql-statement>
  960. SELECT 'indio' NOT LIKE '_ndio' ESCAPE '$' AS "false";
  961. </sql-statement>
  962. <sql-statement>
  963. SELECT 'i_dio' LIKE 'i$_d_o' ESCAPE '$' AS "true";
  964. </sql-statement>
  965. <sql-statement>
  966. SELECT 'i_dio' NOT LIKE 'i$_d_o' ESCAPE '$' AS "false";
  967. </sql-statement>
  968. <sql-statement>
  969. SELECT 'i_dio' LIKE 'i$_nd_o' ESCAPE '$' AS "false";
  970. </sql-statement>
  971. <sql-statement>
  972. SELECT 'i_dio' NOT LIKE 'i$_nd_o' ESCAPE '$' AS "true";
  973. </sql-statement>
  974. <sql-statement>
  975. SELECT 'i_dio' LIKE 'i$_d%o' ESCAPE '$' AS "true";
  976. </sql-statement>
  977. <sql-statement>
  978. SELECT 'i_dio' NOT LIKE 'i$_d%o' ESCAPE '$' AS "false";
  979. </sql-statement>
  980. <sql-statement>
  981. SELECT 'a_c'::bytea LIKE 'a$__'::bytea ESCAPE '$'::bytea AS "true";
  982. </sql-statement>
  983. -stdin-:<main>: Error: Type annotation
  984. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
  985. SELECT 'a_c'::bytea LIKE 'a$__'::bytea ESCAPE '$'::bytea AS "true";
  986. ^
  987. -stdin-:<main>:1:21: Error: At function: PgLike
  988. SELECT 'a_c'::bytea LIKE 'a$__'::bytea ESCAPE '$'::bytea AS "true";
  989. ^
  990. -stdin-:<main>:1:21: Error: Expected pg text, but got bytea
  991. SELECT 'a_c'::bytea LIKE 'a$__'::bytea ESCAPE '$'::bytea AS "true";
  992. ^
  993. <sql-statement>
  994. SELECT 'a_c'::bytea NOT LIKE 'a$__'::bytea ESCAPE '$'::bytea AS "false";
  995. </sql-statement>
  996. -stdin-:<main>: Error: Type annotation
  997. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
  998. SELECT 'a_c'::bytea NOT LIKE 'a$__'::bytea ESCAPE '$'::bytea AS "false";
  999. ^
  1000. -stdin-:<main>:1:21: Error: At function: PgNot, At function: PgLike
  1001. SELECT 'a_c'::bytea NOT LIKE 'a$__'::bytea ESCAPE '$'::bytea AS "false";
  1002. ^
  1003. -stdin-:<main>:1:21: Error: Expected pg text, but got bytea
  1004. SELECT 'a_c'::bytea NOT LIKE 'a$__'::bytea ESCAPE '$'::bytea AS "false";
  1005. ^
  1006. <sql-statement>
  1007. -- escape character same as pattern character
  1008. SELECT 'maca' LIKE 'm%aca' ESCAPE '%' AS "true";
  1009. </sql-statement>
  1010. <sql-statement>
  1011. SELECT 'maca' NOT LIKE 'm%aca' ESCAPE '%' AS "false";
  1012. </sql-statement>
  1013. <sql-statement>
  1014. SELECT 'ma%a' LIKE 'm%a%%a' ESCAPE '%' AS "true";
  1015. </sql-statement>
  1016. <sql-statement>
  1017. SELECT 'ma%a' NOT LIKE 'm%a%%a' ESCAPE '%' AS "false";
  1018. </sql-statement>
  1019. <sql-statement>
  1020. SELECT 'bear' LIKE 'b_ear' ESCAPE '_' AS "true";
  1021. </sql-statement>
  1022. <sql-statement>
  1023. SELECT 'bear' NOT LIKE 'b_ear' ESCAPE '_' AS "false";
  1024. </sql-statement>
  1025. <sql-statement>
  1026. SELECT 'be_r' LIKE 'b_e__r' ESCAPE '_' AS "true";
  1027. </sql-statement>
  1028. <sql-statement>
  1029. SELECT 'be_r' NOT LIKE 'b_e__r' ESCAPE '_' AS "false";
  1030. </sql-statement>
  1031. <sql-statement>
  1032. SELECT 'be_r' LIKE '__e__r' ESCAPE '_' AS "false";
  1033. </sql-statement>
  1034. <sql-statement>
  1035. SELECT 'be_r' NOT LIKE '__e__r' ESCAPE '_' AS "true";
  1036. </sql-statement>
  1037. <sql-statement>
  1038. --
  1039. -- test ILIKE (case-insensitive LIKE)
  1040. -- Be sure to form every test as an ILIKE/NOT ILIKE pair.
  1041. --
  1042. SELECT 'hawkeye' ILIKE 'h%' AS "true";
  1043. </sql-statement>
  1044. <sql-statement>
  1045. SELECT 'hawkeye' NOT ILIKE 'h%' AS "false";
  1046. </sql-statement>
  1047. <sql-statement>
  1048. SELECT 'hawkeye' ILIKE 'H%' AS "true";
  1049. </sql-statement>
  1050. <sql-statement>
  1051. SELECT 'hawkeye' NOT ILIKE 'H%' AS "false";
  1052. </sql-statement>
  1053. <sql-statement>
  1054. SELECT 'hawkeye' ILIKE 'H%Eye' AS "true";
  1055. </sql-statement>
  1056. <sql-statement>
  1057. SELECT 'hawkeye' NOT ILIKE 'H%Eye' AS "false";
  1058. </sql-statement>
  1059. <sql-statement>
  1060. SELECT 'Hawkeye' ILIKE 'h%' AS "true";
  1061. </sql-statement>
  1062. <sql-statement>
  1063. SELECT 'Hawkeye' NOT ILIKE 'h%' AS "false";
  1064. </sql-statement>
  1065. <sql-statement>
  1066. SELECT 'ABC'::name ILIKE '_b_' AS "true";
  1067. </sql-statement>
  1068. <sql-statement>
  1069. SELECT 'ABC'::name NOT ILIKE '_b_' AS "false";
  1070. </sql-statement>
  1071. <sql-statement>
  1072. --
  1073. -- test %/_ combination cases, cf bugs #4821 and #5478
  1074. --
  1075. SELECT 'foo' LIKE '_%' as t, 'f' LIKE '_%' as t, '' LIKE '_%' as f;
  1076. </sql-statement>
  1077. -stdin-:<main>: Error: Type annotation
  1078. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem
  1079. --
  1080. ^
  1081. -stdin-:<main>:1:1: Error: Duplicated member: t
  1082. --
  1083. ^
  1084. <sql-statement>
  1085. SELECT 'foo' LIKE '%_' as t, 'f' LIKE '%_' as t, '' LIKE '%_' as f;
  1086. </sql-statement>
  1087. -stdin-:<main>: Error: Type annotation
  1088. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem
  1089. SELECT 'foo' LIKE '%_' as t, 'f' LIKE '%_' as t, '' LIKE '%_' as f;
  1090. ^
  1091. -stdin-:<main>:1:1: Error: Duplicated member: t
  1092. SELECT 'foo' LIKE '%_' as t, 'f' LIKE '%_' as t, '' LIKE '%_' as f;
  1093. ^
  1094. <sql-statement>
  1095. SELECT 'foo' LIKE '__%' as t, 'foo' LIKE '___%' as t, 'foo' LIKE '____%' as f;
  1096. </sql-statement>
  1097. -stdin-:<main>: Error: Type annotation
  1098. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem
  1099. SELECT 'foo' LIKE '__%' as t, 'foo' LIKE '___%' as t, 'foo' LIKE '____%' as f;
  1100. ^
  1101. -stdin-:<main>:1:1: Error: Duplicated member: t
  1102. SELECT 'foo' LIKE '__%' as t, 'foo' LIKE '___%' as t, 'foo' LIKE '____%' as f;
  1103. ^
  1104. <sql-statement>
  1105. SELECT 'foo' LIKE '%__' as t, 'foo' LIKE '%___' as t, 'foo' LIKE '%____' as f;
  1106. </sql-statement>
  1107. -stdin-:<main>: Error: Type annotation
  1108. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem
  1109. SELECT 'foo' LIKE '%__' as t, 'foo' LIKE '%___' as t, 'foo' LIKE '%____' as f;
  1110. ^
  1111. -stdin-:<main>:1:1: Error: Duplicated member: t
  1112. SELECT 'foo' LIKE '%__' as t, 'foo' LIKE '%___' as t, 'foo' LIKE '%____' as f;
  1113. ^
  1114. <sql-statement>
  1115. SELECT 'jack' LIKE '%____%' AS t;
  1116. </sql-statement>
  1117. <sql-statement>
  1118. --
  1119. -- basic tests of LIKE with indexes
  1120. --
  1121. CREATE TABLE texttest (a text PRIMARY KEY, b int);
  1122. </sql-statement>
  1123. <sql-statement>
  1124. SELECT * FROM texttest WHERE a LIKE '%1%';
  1125. </sql-statement>
  1126. <sql-statement>
  1127. CREATE TABLE byteatest (a bytea PRIMARY KEY, b int);
  1128. </sql-statement>
  1129. <sql-statement>
  1130. SELECT * FROM byteatest WHERE a LIKE '%1%';
  1131. </sql-statement>
  1132. -stdin-:<main>: Error: Type annotation
  1133. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect
  1134. SELECT * FROM byteatest WHERE a LIKE '%1%';
  1135. ^
  1136. -stdin-:<main>: Error: At function: PgSetItem
  1137. -stdin-:<main>:1:1: Error: At function: PgWhere
  1138. SELECT * FROM byteatest WHERE a LIKE '%1%';
  1139. ^
  1140. -stdin-:<main>:1:33: Error: At function: PgLike
  1141. SELECT * FROM byteatest WHERE a LIKE '%1%';
  1142. ^
  1143. -stdin-:<main>:1:33: Error: Expected pg text, but got bytea
  1144. SELECT * FROM byteatest WHERE a LIKE '%1%';
  1145. ^
  1146. <sql-statement>
  1147. DROP TABLE texttest, byteatest;
  1148. </sql-statement>
  1149. <sql-statement>
  1150. --
  1151. -- test implicit type conversion
  1152. --
  1153. -- E021-07 character concatenation
  1154. SELECT 'unknown' || ' and unknown' AS "Concat unknown types";
  1155. </sql-statement>
  1156. <sql-statement>
  1157. SELECT text 'text' || ' and unknown' AS "Concat text to unknown type";
  1158. </sql-statement>
  1159. <sql-statement>
  1160. SELECT char(20) 'characters' || ' and text' AS "Concat char to unknown type";
  1161. </sql-statement>
  1162. <sql-statement>
  1163. SELECT text 'text' || char(20) ' and characters' AS "Concat text to char";
  1164. </sql-statement>
  1165. <sql-statement>
  1166. SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar";
  1167. </sql-statement>
  1168. <sql-statement>
  1169. --
  1170. -- test substr with toasted text values
  1171. --
  1172. CREATE TABLE toasttest(f1 text);
  1173. </sql-statement>
  1174. <sql-statement>
  1175. insert into toasttest values(repeat('1234567890',10000));
  1176. </sql-statement>
  1177. <sql-statement>
  1178. insert into toasttest values(repeat('1234567890',10000));
  1179. </sql-statement>
  1180. <sql-statement>
  1181. --
  1182. -- Ensure that some values are uncompressed, to test the faster substring
  1183. -- operation used in that case
  1184. --
  1185. alter table toasttest alter column f1 set storage external;
  1186. </sql-statement>
  1187. -stdin-:<main>: Error: Parse Sql
  1188. -stdin-:<main>:1:1: Error: alternative is not implemented yet : 245
  1189. --
  1190. ^
  1191. <sql-statement>
  1192. insert into toasttest values(repeat('1234567890',10000));
  1193. </sql-statement>
  1194. <sql-statement>
  1195. insert into toasttest values(repeat('1234567890',10000));
  1196. </sql-statement>
  1197. <sql-statement>
  1198. -- If the starting position is zero or less, then return from the start of the string
  1199. -- adjusting the length to be consistent with the "negative start" per SQL.
  1200. SELECT substr(f1, -1, 5) from toasttest;
  1201. </sql-statement>
  1202. <sql-statement>
  1203. -- If the length is less than zero, an ERROR is thrown.
  1204. SELECT substr(f1, 5, -1) from toasttest;
  1205. </sql-statement>
  1206. -stdin-:<main>: Fatal: Execution
  1207. -stdin-:<main>:1:1: Fatal: Execution of node: YtMap!
  1208. -- If the length is less than zero, an ERROR is thrown.
  1209. ^
  1210. -stdin-:<main>:1:1: Fatal: ERROR: negative substring length not allowed
  1211. -- If the length is less than zero, an ERROR is thrown.
  1212. ^
  1213. <sql-statement>
  1214. -- If no third argument (length) is provided, the length to the end of the
  1215. -- string is assumed.
  1216. SELECT substr(f1, 99995) from toasttest;
  1217. </sql-statement>
  1218. <sql-statement>
  1219. -- If start plus length is > string length, the result is truncated to
  1220. -- string length
  1221. SELECT substr(f1, 99995, 10) from toasttest;
  1222. </sql-statement>
  1223. <sql-statement>
  1224. TRUNCATE TABLE toasttest;
  1225. </sql-statement>
  1226. -stdin-:<main>: Error: Parse Sql
  1227. -stdin-:<main>:1:1: Error: RawStmt: alternative is not implemented yet : 257
  1228. TRUNCATE TABLE toasttest;
  1229. ^
  1230. <sql-statement>
  1231. INSERT INTO toasttest values (repeat('1234567890',300));
  1232. </sql-statement>
  1233. <sql-statement>
  1234. INSERT INTO toasttest values (repeat('1234567890',300));
  1235. </sql-statement>
  1236. <sql-statement>
  1237. INSERT INTO toasttest values (repeat('1234567890',300));
  1238. </sql-statement>
  1239. <sql-statement>
  1240. INSERT INTO toasttest values (repeat('1234567890',300));
  1241. </sql-statement>
  1242. <sql-statement>
  1243. -- expect >0 blocks
  1244. SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
  1245. FROM pg_class where relname = 'toasttest';
  1246. </sql-statement>
  1247. -stdin-:<main>: Error: Type annotation
  1248. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
  1249. -- expect >0 blocks
  1250. ^
  1251. -stdin-:<main>:2:40: Error: At function: PgOp
  1252. SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
  1253. ^
  1254. -stdin-:<main>:2:8: Error: At function: PgCall
  1255. SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
  1256. ^
  1257. -stdin-:<main>:2:8: Error: Unable to find an overload for proc pg_relation_size with given argument types: (oid)
  1258. SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
  1259. ^
  1260. <sql-statement>
  1261. TRUNCATE TABLE toasttest;
  1262. </sql-statement>
  1263. -stdin-:<main>: Error: Parse Sql
  1264. -stdin-:<main>:1:1: Error: RawStmt: alternative is not implemented yet : 257
  1265. TRUNCATE TABLE toasttest;
  1266. ^
  1267. <sql-statement>
  1268. ALTER TABLE toasttest set (toast_tuple_target = 4080);
  1269. </sql-statement>
  1270. -stdin-:<main>: Error: Parse Sql
  1271. -stdin-:<main>:1:1: Error: alternative is not implemented yet : 245
  1272. ALTER TABLE toasttest set (toast_tuple_target = 4080);
  1273. ^
  1274. <sql-statement>
  1275. INSERT INTO toasttest values (repeat('1234567890',300));
  1276. </sql-statement>
  1277. <sql-statement>
  1278. INSERT INTO toasttest values (repeat('1234567890',300));
  1279. </sql-statement>
  1280. <sql-statement>
  1281. INSERT INTO toasttest values (repeat('1234567890',300));
  1282. </sql-statement>
  1283. <sql-statement>
  1284. INSERT INTO toasttest values (repeat('1234567890',300));
  1285. </sql-statement>
  1286. <sql-statement>
  1287. -- expect 0 blocks
  1288. SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
  1289. FROM pg_class where relname = 'toasttest';
  1290. </sql-statement>
  1291. -stdin-:<main>: Error: Type annotation
  1292. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
  1293. -- expect 0 blocks
  1294. ^
  1295. -stdin-:<main>:2:40: Error: At function: PgOp
  1296. SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
  1297. ^
  1298. -stdin-:<main>:2:8: Error: At function: PgCall
  1299. SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
  1300. ^
  1301. -stdin-:<main>:2:8: Error: Unable to find an overload for proc pg_relation_size with given argument types: (oid)
  1302. SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
  1303. ^
  1304. <sql-statement>
  1305. DROP TABLE toasttest;
  1306. </sql-statement>
  1307. <sql-statement>
  1308. --
  1309. -- test substr with toasted bytea values
  1310. --
  1311. CREATE TABLE toasttest(f1 bytea);
  1312. </sql-statement>
  1313. <sql-statement>
  1314. insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
  1315. </sql-statement>
  1316. <sql-statement>
  1317. insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
  1318. </sql-statement>
  1319. <sql-statement>
  1320. --
  1321. -- Ensure that some values are uncompressed, to test the faster substring
  1322. -- operation used in that case
  1323. --
  1324. alter table toasttest alter column f1 set storage external;
  1325. </sql-statement>
  1326. -stdin-:<main>: Error: Parse Sql
  1327. -stdin-:<main>:1:1: Error: alternative is not implemented yet : 245
  1328. --
  1329. ^
  1330. <sql-statement>
  1331. insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
  1332. </sql-statement>
  1333. <sql-statement>
  1334. insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
  1335. </sql-statement>
  1336. <sql-statement>
  1337. -- If the starting position is zero or less, then return from the start of the string
  1338. -- adjusting the length to be consistent with the "negative start" per SQL.
  1339. SELECT substr(f1, -1, 5) from toasttest;
  1340. </sql-statement>
  1341. <sql-statement>
  1342. -- If the length is less than zero, an ERROR is thrown.
  1343. SELECT substr(f1, 5, -1) from toasttest;
  1344. </sql-statement>
  1345. -stdin-:<main>: Fatal: Execution
  1346. -stdin-:<main>:1:1: Fatal: Execution of node: YtMap!
  1347. -- If the length is less than zero, an ERROR is thrown.
  1348. ^
  1349. -stdin-:<main>:1:1: Fatal: ERROR: negative substring length not allowed
  1350. -- If the length is less than zero, an ERROR is thrown.
  1351. ^
  1352. <sql-statement>
  1353. -- If no third argument (length) is provided, the length to the end of the
  1354. -- string is assumed.
  1355. SELECT substr(f1, 99995) from toasttest;
  1356. </sql-statement>
  1357. <sql-statement>
  1358. -- If start plus length is > string length, the result is truncated to
  1359. -- string length
  1360. SELECT substr(f1, 99995, 10) from toasttest;
  1361. </sql-statement>
  1362. <sql-statement>
  1363. DROP TABLE toasttest;
  1364. </sql-statement>
  1365. <sql-statement>
  1366. -- test internally compressing datums
  1367. -- this tests compressing a datum to a very small size which exercises a
  1368. -- corner case in packed-varlena handling: even though small, the compressed
  1369. -- datum must be given a 4-byte header because there are no bits to indicate
  1370. -- compression in a 1-byte header
  1371. CREATE TABLE toasttest (c char(4096));
  1372. </sql-statement>
  1373. <sql-statement>
  1374. INSERT INTO toasttest VALUES('x');
  1375. </sql-statement>
  1376. <sql-statement>
  1377. SELECT length(c), c::text FROM toasttest;
  1378. </sql-statement>
  1379. <sql-statement>
  1380. SELECT c FROM toasttest;
  1381. </sql-statement>
  1382. <sql-statement>
  1383. DROP TABLE toasttest;
  1384. </sql-statement>
  1385. <sql-statement>
  1386. --
  1387. -- test length
  1388. --
  1389. SELECT length('abcdef') AS "length_6";
  1390. </sql-statement>
  1391. <sql-statement>
  1392. --
  1393. -- test strpos
  1394. --
  1395. SELECT strpos('abcdef', 'cd') AS "pos_3";
  1396. </sql-statement>
  1397. <sql-statement>
  1398. SELECT strpos('abcdef', 'xy') AS "pos_0";
  1399. </sql-statement>
  1400. <sql-statement>
  1401. SELECT strpos('abcdef', '') AS "pos_1";
  1402. </sql-statement>
  1403. <sql-statement>
  1404. SELECT strpos('', 'xy') AS "pos_0";
  1405. </sql-statement>
  1406. <sql-statement>
  1407. SELECT strpos('', '') AS "pos_1";
  1408. </sql-statement>
  1409. <sql-statement>
  1410. --
  1411. -- test replace
  1412. --
  1413. SELECT replace('abcdef', 'de', '45') AS "abc45f";
  1414. </sql-statement>
  1415. <sql-statement>
  1416. SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo";
  1417. </sql-statement>
  1418. <sql-statement>
  1419. SELECT replace('yabadoo', 'bad', '') AS "yaoo";
  1420. </sql-statement>
  1421. <sql-statement>
  1422. --
  1423. -- test split_part
  1424. --
  1425. select split_part('','@',1) AS "empty string";
  1426. </sql-statement>
  1427. <sql-statement>
  1428. select split_part('','@',-1) AS "empty string";
  1429. </sql-statement>
  1430. <sql-statement>
  1431. select split_part('joeuser@mydatabase','',1) AS "joeuser@mydatabase";
  1432. </sql-statement>
  1433. <sql-statement>
  1434. select split_part('joeuser@mydatabase','',2) AS "empty string";
  1435. </sql-statement>
  1436. <sql-statement>
  1437. select split_part('joeuser@mydatabase','',-1) AS "joeuser@mydatabase";
  1438. </sql-statement>
  1439. <sql-statement>
  1440. select split_part('joeuser@mydatabase','',-2) AS "empty string";
  1441. </sql-statement>
  1442. <sql-statement>
  1443. select split_part('joeuser@mydatabase','@',0) AS "an error";
  1444. </sql-statement>
  1445. -stdin-:<main>: Fatal: Execution
  1446. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1447. select split_part('joeuser@mydatabase','@',0) AS "an error";
  1448. ^
  1449. -stdin-:<main>:1:1: Fatal: ERROR: field position must not be zero
  1450. select split_part('joeuser@mydatabase','@',0) AS "an error";
  1451. ^
  1452. <sql-statement>
  1453. select split_part('joeuser@mydatabase','@@',1) AS "joeuser@mydatabase";
  1454. </sql-statement>
  1455. <sql-statement>
  1456. select split_part('joeuser@mydatabase','@@',2) AS "empty string";
  1457. </sql-statement>
  1458. <sql-statement>
  1459. select split_part('joeuser@mydatabase','@',1) AS "joeuser";
  1460. </sql-statement>
  1461. <sql-statement>
  1462. select split_part('joeuser@mydatabase','@',2) AS "mydatabase";
  1463. </sql-statement>
  1464. <sql-statement>
  1465. select split_part('joeuser@mydatabase','@',3) AS "empty string";
  1466. </sql-statement>
  1467. <sql-statement>
  1468. select split_part('@joeuser@mydatabase@','@',2) AS "joeuser";
  1469. </sql-statement>
  1470. <sql-statement>
  1471. select split_part('joeuser@mydatabase','@',-1) AS "mydatabase";
  1472. </sql-statement>
  1473. <sql-statement>
  1474. select split_part('joeuser@mydatabase','@',-2) AS "joeuser";
  1475. </sql-statement>
  1476. <sql-statement>
  1477. select split_part('joeuser@mydatabase','@',-3) AS "empty string";
  1478. </sql-statement>
  1479. <sql-statement>
  1480. select split_part('@joeuser@mydatabase@','@',-2) AS "mydatabase";
  1481. </sql-statement>
  1482. <sql-statement>
  1483. --
  1484. -- test to_hex
  1485. --
  1486. select to_hex(256*256*256 - 1) AS "ffffff";
  1487. </sql-statement>
  1488. <sql-statement>
  1489. select to_hex(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "ffffffff";
  1490. </sql-statement>
  1491. <sql-statement>
  1492. --
  1493. -- MD5 test suite - from IETF RFC 1321
  1494. -- (see: ftp://ftp.rfc-editor.org/in-notes/rfc1321.txt)
  1495. --
  1496. select md5('') = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
  1497. </sql-statement>
  1498. <sql-statement>
  1499. select md5('a') = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
  1500. </sql-statement>
  1501. <sql-statement>
  1502. select md5('abc') = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
  1503. </sql-statement>
  1504. <sql-statement>
  1505. select md5('message digest') = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
  1506. </sql-statement>
  1507. <sql-statement>
  1508. select md5('abcdefghijklmnopqrstuvwxyz') = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
  1509. </sql-statement>
  1510. <sql-statement>
  1511. select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
  1512. </sql-statement>
  1513. <sql-statement>
  1514. select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
  1515. </sql-statement>
  1516. <sql-statement>
  1517. select md5(''::bytea) = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
  1518. </sql-statement>
  1519. <sql-statement>
  1520. select md5('a'::bytea) = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
  1521. </sql-statement>
  1522. <sql-statement>
  1523. select md5('abc'::bytea) = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
  1524. </sql-statement>
  1525. <sql-statement>
  1526. select md5('message digest'::bytea) = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
  1527. </sql-statement>
  1528. <sql-statement>
  1529. select md5('abcdefghijklmnopqrstuvwxyz'::bytea) = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
  1530. </sql-statement>
  1531. <sql-statement>
  1532. select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'::bytea) = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
  1533. </sql-statement>
  1534. <sql-statement>
  1535. select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890'::bytea) = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
  1536. </sql-statement>
  1537. <sql-statement>
  1538. --
  1539. -- SHA-2
  1540. --
  1541. SET bytea_output TO hex;
  1542. </sql-statement>
  1543. <sql-statement>
  1544. SELECT sha224('');
  1545. </sql-statement>
  1546. <sql-statement>
  1547. SELECT sha224('The quick brown fox jumps over the lazy dog.');
  1548. </sql-statement>
  1549. <sql-statement>
  1550. SELECT sha256('');
  1551. </sql-statement>
  1552. <sql-statement>
  1553. SELECT sha256('The quick brown fox jumps over the lazy dog.');
  1554. </sql-statement>
  1555. <sql-statement>
  1556. SELECT sha384('');
  1557. </sql-statement>
  1558. <sql-statement>
  1559. SELECT sha384('The quick brown fox jumps over the lazy dog.');
  1560. </sql-statement>
  1561. <sql-statement>
  1562. SELECT sha512('');
  1563. </sql-statement>
  1564. <sql-statement>
  1565. SELECT sha512('The quick brown fox jumps over the lazy dog.');
  1566. </sql-statement>
  1567. <sql-statement>
  1568. --
  1569. -- encode/decode
  1570. --
  1571. SELECT encode('\x1234567890abcdef00', 'hex');
  1572. </sql-statement>
  1573. <sql-statement>
  1574. SELECT decode('1234567890abcdef00', 'hex');
  1575. </sql-statement>
  1576. <sql-statement>
  1577. SELECT encode(('\x' || repeat('1234567890abcdef0001', 7))::bytea, 'base64');
  1578. </sql-statement>
  1579. <sql-statement>
  1580. SELECT decode(encode(('\x' || repeat('1234567890abcdef0001', 7))::bytea,
  1581. 'base64'), 'base64');
  1582. </sql-statement>
  1583. <sql-statement>
  1584. SELECT encode('\x1234567890abcdef00', 'escape');
  1585. </sql-statement>
  1586. <sql-statement>
  1587. SELECT decode(encode('\x1234567890abcdef00', 'escape'), 'escape');
  1588. </sql-statement>
  1589. <sql-statement>
  1590. --
  1591. -- get_bit/set_bit etc
  1592. --
  1593. SELECT get_bit('\x1234567890abcdef00'::bytea, 43);
  1594. </sql-statement>
  1595. <sql-statement>
  1596. SELECT get_bit('\x1234567890abcdef00'::bytea, 99); -- error
  1597. </sql-statement>
  1598. -stdin-:<main>: Fatal: Execution
  1599. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1600. SELECT get_bit('\x1234567890abcdef00'::bytea, 99); -- error
  1601. ^
  1602. -stdin-:<main>:1:1: Fatal: ERROR: index 99 out of valid range, 0..71
  1603. SELECT get_bit('\x1234567890abcdef00'::bytea, 99); -- error
  1604. ^
  1605. <sql-statement>
  1606. SELECT set_bit('\x1234567890abcdef00'::bytea, 43, 0);
  1607. </sql-statement>
  1608. <sql-statement>
  1609. SELECT set_bit('\x1234567890abcdef00'::bytea, 99, 0); -- error
  1610. </sql-statement>
  1611. -stdin-:<main>: Fatal: Execution
  1612. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1613. SELECT set_bit('\x1234567890abcdef00'::bytea, 99, 0); -- error
  1614. ^
  1615. -stdin-:<main>:1:1: Fatal: ERROR: index 99 out of valid range, 0..71
  1616. SELECT set_bit('\x1234567890abcdef00'::bytea, 99, 0); -- error
  1617. ^
  1618. <sql-statement>
  1619. SELECT get_byte('\x1234567890abcdef00'::bytea, 3);
  1620. </sql-statement>
  1621. <sql-statement>
  1622. SELECT get_byte('\x1234567890abcdef00'::bytea, 99); -- error
  1623. </sql-statement>
  1624. -stdin-:<main>: Fatal: Execution
  1625. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1626. SELECT get_byte('\x1234567890abcdef00'::bytea, 99); -- error
  1627. ^
  1628. -stdin-:<main>:1:1: Fatal: ERROR: index 99 out of valid range, 0..8
  1629. SELECT get_byte('\x1234567890abcdef00'::bytea, 99); -- error
  1630. ^
  1631. <sql-statement>
  1632. SELECT set_byte('\x1234567890abcdef00'::bytea, 7, 11);
  1633. </sql-statement>
  1634. <sql-statement>
  1635. SELECT set_byte('\x1234567890abcdef00'::bytea, 99, 11); -- error
  1636. </sql-statement>
  1637. -stdin-:<main>: Fatal: Execution
  1638. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1639. SELECT set_byte('\x1234567890abcdef00'::bytea, 99, 11); -- error
  1640. ^
  1641. -stdin-:<main>:1:1: Fatal: ERROR: index 99 out of valid range, 0..8
  1642. SELECT set_byte('\x1234567890abcdef00'::bytea, 99, 11); -- error
  1643. ^
  1644. <sql-statement>
  1645. --
  1646. -- test behavior of escape_string_warning and standard_conforming_strings options
  1647. --
  1648. set escape_string_warning = off;
  1649. </sql-statement>
  1650. <sql-statement>
  1651. set standard_conforming_strings = off;
  1652. </sql-statement>
  1653. <sql-statement>
  1654. show escape_string_warning;
  1655. </sql-statement>
  1656. -stdin-:<main>: Error: Parse Sql
  1657. -stdin-:<main>:1:1: Error: unrecognized configuration parameter "escape_string_warning"
  1658. show escape_string_warning;
  1659. ^
  1660. <sql-statement>
  1661. show standard_conforming_strings;
  1662. </sql-statement>
  1663. <sql-statement>
  1664. set escape_string_warning = on;
  1665. </sql-statement>
  1666. <sql-statement>
  1667. set standard_conforming_strings = on;
  1668. </sql-statement>
  1669. <sql-statement>
  1670. show escape_string_warning;
  1671. </sql-statement>
  1672. -stdin-:<main>: Error: Parse Sql
  1673. -stdin-:<main>:1:1: Error: unrecognized configuration parameter "escape_string_warning"
  1674. show escape_string_warning;
  1675. ^
  1676. <sql-statement>
  1677. show standard_conforming_strings;
  1678. </sql-statement>
  1679. <sql-statement>
  1680. select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;
  1681. </sql-statement>
  1682. <sql-statement>
  1683. set standard_conforming_strings = off;
  1684. </sql-statement>
  1685. <sql-statement>
  1686. select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
  1687. </sql-statement>
  1688. -stdin-:<main>: Error: Parse Sql
  1689. -stdin-:<main>:1:34: Error: ERROR: syntax error at or near "' as f2, '"
  1690. select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
  1691. ^
  1692. <sql-statement>
  1693. set escape_string_warning = off;
  1694. </sql-statement>
  1695. <sql-statement>
  1696. set standard_conforming_strings = on;
  1697. </sql-statement>
  1698. <sql-statement>
  1699. select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;
  1700. </sql-statement>
  1701. <sql-statement>
  1702. set standard_conforming_strings = off;
  1703. </sql-statement>
  1704. <sql-statement>
  1705. select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
  1706. </sql-statement>
  1707. -stdin-:<main>: Error: Parse Sql
  1708. -stdin-:<main>:1:34: Error: ERROR: syntax error at or near "' as f2, '"
  1709. select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
  1710. ^
  1711. <sql-statement>
  1712. reset standard_conforming_strings;
  1713. </sql-statement>
  1714. <sql-statement>
  1715. --
  1716. -- Additional string functions
  1717. --
  1718. SET bytea_output TO escape;
  1719. </sql-statement>
  1720. <sql-statement>
  1721. SELECT initcap('hi THOMAS');
  1722. </sql-statement>
  1723. <sql-statement>
  1724. SELECT lpad('hi', 5, 'xy');
  1725. </sql-statement>
  1726. <sql-statement>
  1727. SELECT lpad('hi', 5);
  1728. </sql-statement>
  1729. -stdin-:<main>: Error: Type annotation
  1730. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
  1731. SELECT lpad('hi', 5);
  1732. ^
  1733. -stdin-:<main>:1:8: Error: At function: PgCall
  1734. SELECT lpad('hi', 5);
  1735. ^
  1736. -stdin-:<main>:1:8: Error: Unable to find an overload for proc lpad with given argument types: (unknown,int4)
  1737. SELECT lpad('hi', 5);
  1738. ^
  1739. <sql-statement>
  1740. SELECT lpad('hi', -5, 'xy');
  1741. </sql-statement>
  1742. <sql-statement>
  1743. SELECT lpad('hello', 2);
  1744. </sql-statement>
  1745. -stdin-:<main>: Error: Type annotation
  1746. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
  1747. SELECT lpad('hello', 2);
  1748. ^
  1749. -stdin-:<main>:1:8: Error: At function: PgCall
  1750. SELECT lpad('hello', 2);
  1751. ^
  1752. -stdin-:<main>:1:8: Error: Unable to find an overload for proc lpad with given argument types: (unknown,int4)
  1753. SELECT lpad('hello', 2);
  1754. ^
  1755. <sql-statement>
  1756. SELECT lpad('hi', 5, '');
  1757. </sql-statement>
  1758. <sql-statement>
  1759. SELECT rpad('hi', 5, 'xy');
  1760. </sql-statement>
  1761. <sql-statement>
  1762. SELECT rpad('hi', 5);
  1763. </sql-statement>
  1764. -stdin-:<main>: Error: Type annotation
  1765. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
  1766. SELECT rpad('hi', 5);
  1767. ^
  1768. -stdin-:<main>:1:8: Error: At function: PgCall
  1769. SELECT rpad('hi', 5);
  1770. ^
  1771. -stdin-:<main>:1:8: Error: Unable to find an overload for proc rpad with given argument types: (unknown,int4)
  1772. SELECT rpad('hi', 5);
  1773. ^
  1774. <sql-statement>
  1775. SELECT rpad('hi', -5, 'xy');
  1776. </sql-statement>
  1777. <sql-statement>
  1778. SELECT rpad('hello', 2);
  1779. </sql-statement>
  1780. -stdin-:<main>: Error: Type annotation
  1781. -stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
  1782. SELECT rpad('hello', 2);
  1783. ^
  1784. -stdin-:<main>:1:8: Error: At function: PgCall
  1785. SELECT rpad('hello', 2);
  1786. ^
  1787. -stdin-:<main>:1:8: Error: Unable to find an overload for proc rpad with given argument types: (unknown,int4)
  1788. SELECT rpad('hello', 2);
  1789. ^
  1790. <sql-statement>
  1791. SELECT rpad('hi', 5, '');
  1792. </sql-statement>
  1793. <sql-statement>
  1794. SELECT ltrim('zzzytrim', 'xyz');
  1795. </sql-statement>
  1796. <sql-statement>
  1797. SELECT translate('', '14', 'ax');
  1798. </sql-statement>
  1799. <sql-statement>
  1800. SELECT translate('12345', '14', 'ax');
  1801. </sql-statement>
  1802. <sql-statement>
  1803. SELECT ascii('x');
  1804. </sql-statement>
  1805. <sql-statement>
  1806. SELECT ascii('');
  1807. </sql-statement>
  1808. <sql-statement>
  1809. SELECT chr(65);
  1810. </sql-statement>
  1811. <sql-statement>
  1812. SELECT chr(0);
  1813. </sql-statement>
  1814. -stdin-:<main>: Fatal: Execution
  1815. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1816. SELECT chr(0);
  1817. ^
  1818. -stdin-:<main>:1:1: Fatal: ERROR: null character not permitted
  1819. SELECT chr(0);
  1820. ^
  1821. <sql-statement>
  1822. SELECT repeat('Pg', 4);
  1823. </sql-statement>
  1824. <sql-statement>
  1825. SELECT repeat('Pg', -4);
  1826. </sql-statement>
  1827. <sql-statement>
  1828. SELECT SUBSTRING('1234567890'::bytea FROM 3) "34567890";
  1829. </sql-statement>
  1830. <sql-statement>
  1831. SELECT SUBSTRING('1234567890'::bytea FROM 4 FOR 3) AS "456";
  1832. </sql-statement>
  1833. <sql-statement>
  1834. SELECT SUBSTRING('string'::bytea FROM 2 FOR 2147483646) AS "tring";
  1835. </sql-statement>
  1836. <sql-statement>
  1837. SELECT SUBSTRING('string'::bytea FROM -10 FOR 2147483646) AS "string";
  1838. </sql-statement>
  1839. <sql-statement>
  1840. SELECT SUBSTRING('string'::bytea FROM -10 FOR -2147483646) AS "error";
  1841. </sql-statement>
  1842. -stdin-:<main>: Fatal: Execution
  1843. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1844. SELECT SUBSTRING('string'::bytea FROM -10 FOR -2147483646) AS "error";
  1845. ^
  1846. -stdin-:<main>:1:1: Fatal: ERROR: negative substring length not allowed
  1847. SELECT SUBSTRING('string'::bytea FROM -10 FOR -2147483646) AS "error";
  1848. ^
  1849. <sql-statement>
  1850. SELECT trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea);
  1851. </sql-statement>
  1852. <sql-statement>
  1853. SELECT trim(leading E'\\000'::bytea from E'\\000Tom\\000'::bytea);
  1854. </sql-statement>
  1855. <sql-statement>
  1856. SELECT trim(trailing E'\\000'::bytea from E'\\000Tom\\000'::bytea);
  1857. </sql-statement>
  1858. <sql-statement>
  1859. SELECT btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea);
  1860. </sql-statement>
  1861. <sql-statement>
  1862. SELECT btrim(''::bytea, E'\\000'::bytea);
  1863. </sql-statement>
  1864. <sql-statement>
  1865. SELECT btrim(E'\\000trim\\000'::bytea, ''::bytea);
  1866. </sql-statement>
  1867. <sql-statement>
  1868. SELECT encode(overlay(E'Th\\000omas'::bytea placing E'Th\\001omas'::bytea from 2),'escape');
  1869. </sql-statement>
  1870. <sql-statement>
  1871. SELECT encode(overlay(E'Th\\000omas'::bytea placing E'\\002\\003'::bytea from 8),'escape');
  1872. </sql-statement>
  1873. <sql-statement>
  1874. SELECT encode(overlay(E'Th\\000omas'::bytea placing E'\\002\\003'::bytea from 5 for 3),'escape');
  1875. </sql-statement>
  1876. <sql-statement>
  1877. SELECT bit_count('\x1234567890'::bytea);
  1878. </sql-statement>
  1879. <sql-statement>
  1880. SELECT unistr('\0064at\+0000610');
  1881. </sql-statement>
  1882. <sql-statement>
  1883. SELECT unistr('d\u0061t\U000000610');
  1884. </sql-statement>
  1885. <sql-statement>
  1886. SELECT unistr('a\\b');
  1887. </sql-statement>
  1888. <sql-statement>
  1889. -- errors:
  1890. SELECT unistr('wrong: \db99');
  1891. </sql-statement>
  1892. -stdin-:<main>: Fatal: Execution
  1893. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1894. -- errors:
  1895. ^
  1896. -stdin-:<main>:1:1: Fatal: ERROR: invalid Unicode surrogate pair
  1897. -- errors:
  1898. ^
  1899. <sql-statement>
  1900. SELECT unistr('wrong: \db99\0061');
  1901. </sql-statement>
  1902. -stdin-:<main>: Fatal: Execution
  1903. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1904. SELECT unistr('wrong: \db99\0061');
  1905. ^
  1906. -stdin-:<main>:1:1: Fatal: ERROR: invalid Unicode surrogate pair
  1907. SELECT unistr('wrong: \db99\0061');
  1908. ^
  1909. <sql-statement>
  1910. SELECT unistr('wrong: \+00db99\+000061');
  1911. </sql-statement>
  1912. -stdin-:<main>: Fatal: Execution
  1913. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1914. SELECT unistr('wrong: \+00db99\+000061');
  1915. ^
  1916. -stdin-:<main>:1:1: Fatal: ERROR: invalid Unicode surrogate pair
  1917. SELECT unistr('wrong: \+00db99\+000061');
  1918. ^
  1919. <sql-statement>
  1920. SELECT unistr('wrong: \+2FFFFF');
  1921. </sql-statement>
  1922. -stdin-:<main>: Fatal: Execution
  1923. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1924. SELECT unistr('wrong: \+2FFFFF');
  1925. ^
  1926. -stdin-:<main>:1:1: Fatal: ERROR: invalid Unicode code point: 2FFFFF
  1927. SELECT unistr('wrong: \+2FFFFF');
  1928. ^
  1929. <sql-statement>
  1930. SELECT unistr('wrong: \udb99\u0061');
  1931. </sql-statement>
  1932. -stdin-:<main>: Fatal: Execution
  1933. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1934. SELECT unistr('wrong: \udb99\u0061');
  1935. ^
  1936. -stdin-:<main>:1:1: Fatal: ERROR: invalid Unicode surrogate pair
  1937. SELECT unistr('wrong: \udb99\u0061');
  1938. ^
  1939. <sql-statement>
  1940. SELECT unistr('wrong: \U0000db99\U00000061');
  1941. </sql-statement>
  1942. -stdin-:<main>: Fatal: Execution
  1943. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1944. SELECT unistr('wrong: \U0000db99\U00000061');
  1945. ^
  1946. -stdin-:<main>:1:1: Fatal: ERROR: invalid Unicode surrogate pair
  1947. SELECT unistr('wrong: \U0000db99\U00000061');
  1948. ^
  1949. <sql-statement>
  1950. SELECT unistr('wrong: \U002FFFFF');
  1951. </sql-statement>
  1952. -stdin-:<main>: Fatal: Execution
  1953. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1954. SELECT unistr('wrong: \U002FFFFF');
  1955. ^
  1956. -stdin-:<main>:1:1: Fatal: ERROR: invalid Unicode code point: 2FFFFF
  1957. SELECT unistr('wrong: \U002FFFFF');
  1958. ^
  1959. <sql-statement>
  1960. SELECT unistr('wrong: \xyz');
  1961. </sql-statement>
  1962. -stdin-:<main>: Fatal: Execution
  1963. -stdin-:<main>:1:1: Fatal: Execution of node: Result
  1964. SELECT unistr('wrong: \xyz');
  1965. ^
  1966. -stdin-:<main>:1:1: Fatal: ERROR: invalid Unicode escape
  1967. HINT: Unicode escapes must be \XXXX, \+XXXXXX, \uXXXX, or \UXXXXXXXX.
  1968. SELECT unistr('wrong: \xyz');
  1969. ^