1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840 |
- # Copyright Materialize, Inc. and contributors. All rights reserved.
- #
- # Use of this software is governed by the Business Source License
- # included in the LICENSE file at the root of this repository.
- #
- # As of the Change Date specified in that file, in accordance with
- # the Business Source License, use of this software will be governed
- # by the Apache License, Version 2.0.
- mode cockroach
- ### column names ###
- query TTT colnames
- SELECT length('a'), ascii('a'), substr('a', 1) LIMIT 0
- ----
- length ascii substr
- query T colnames
- SELECT length(column1) FROM (VALUES ('a')) GROUP BY length(column1) LIMIT 0
- ----
- length
- query T colnames
- SELECT column1::text FROM (VALUES ('a')) LIMIT 0
- ----
- column1
- ### ascii ###
- statement ok
- CREATE TABLE asciitest (strcol CHAR(15), vccol VARCHAR(15))
- statement ok
- INSERT INTO asciitest VALUES ('hello world', 'goodbye moon'), (NULL, NULL),
- ('你好', '再见'), ('😀', '👻'), ('',''), (' ', ' ');
- statement error
- SELECT ascii(98)
- query II colnames
- SELECT ascii(strcol) AS strres, ascii(vccol) AS vcres FROM asciitest ORDER BY strres
- ----
- strres vcres
- 0 0
- 0 32
- 104 103
- 20320 20877
- 128512 128123
- NULL NULL
- query I
- SELECT ascii(NULL)
- ----
- NULL
- query I
- SELECT ascii(substr('inside literal', 3, 4))
- ----
- 115
- ### substr ###
- statement ok
- CREATE TABLE substrtest (strcol char(15), vccol varchar(15), smicol smallint, intcol int)
- statement ok
- INSERT INTO substrtest VALUES ('Mg', 'Mn', 1, 1), ('magnesium', 'manganese', 3, NULL),
- (NULL, NULL, 0, 0), ('24.31', '54.94', 2, 3), ('长久不见', '爱不释手', NULL, 2),
- ('', '', -1, 2)
- # invalid input
- statement error
- SELECT substr(192, 1, 1)
- statement error
- SELECT substr('from wrong type', 1.5, 2)
- statement error
- SELECT substr('for wrong type', 2, 1.5)
- query error negative substring length not allowed
- SELECT substr('for cannot be negative', 1, -3)
- query error negative substring length not allowed
- SELECT substr('for still cannot be negative', 30, -2)
- query B
- SELECT substr('hello', 2) IS NULL
- ----
- false
- query B
- SELECT substr(NULL, 2) IS NULL
- ----
- true
- query B
- SELECT substr('hello', NULL) IS NULL
- ----
- true
- query B
- SELECT substr(NULL, 2, 3) IS NULL
- ----
- true
- query B
- SELECT substr('hello', NULL, 3) IS NULL
- ----
- true
- query B
- SELECT substr('hello', 2, NULL) IS NULL
- ----
- true
- query error division by zero
- SELECT substr('hello', 0/0, 3)
- # standard tests
- query T colnames,rowsort
- SELECT to_jsonb(strcol) as strcol FROM substrtest
- ----
- strcol
- NULL
- " "
- "24.31 "
- "Mg "
- "magnesium "
- "长久不见 "
- query T colnames
- SELECT substr(vccol, 1, 3) AS vcres FROM substrtest ORDER BY vcres
- ----
- vcres
- (empty)
- 54.
- Mn
- man
- 爱不释
- NULL
- query T colnames
- SELECT substr(vccol, 1, 5) AS vcres FROM substrtest ORDER BY vcres
- ----
- vcres
- (empty)
- 54.94
- Mn
- manga
- 爱不释手
- NULL
- query T colnames
- SELECT substr(vccol, 1) AS vcres FROM substrtest ORDER BY vcres
- ----
- vcres
- (empty)
- 54.94
- Mn
- manganese
- 爱不释手
- NULL
- query T colnames
- SELECT substr(vccol, 3) AS vcres FROM substrtest ORDER BY vcres
- ----
- vcres
- (empty)
- (empty)
- .94
- nganese
- 释手
- NULL
- query T colnames
- SELECT substr(vccol, 3, 1) AS vcres FROM substrtest ORDER BY vcres
- ----
- vcres
- (empty)
- (empty)
- .
- n
- 释
- NULL
- # negative start position
- query T colnames
- SELECT substr(vccol, -1) AS vcres FROM substrtest ORDER BY vcres
- ----
- vcres
- (empty)
- 54.94
- Mn
- manganese
- 爱不释手
- NULL
- query T colnames
- SELECT substr(vccol, -2, 6) AS vcres FROM substrtest ORDER BY vcres
- ----
- vcres
- (empty)
- 54.
- Mn
- man
- 爱不释
- NULL
- query T colnames
- SELECT substr(vccol, -3, 5) AS vcres FROM substrtest ORDER BY vcres
- ----
- vcres
- (empty)
- 5
- M
- m
- 爱
- NULL
- query TT colnames
- SELECT substr(strcol, -4, 5) AS strres, substr(vccol, -4, 5) AS vcres FROM substrtest ORDER BY vcres
- ----
- strres vcres
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- NULL NULL
- query TT colnames
- SELECT substr(strcol, -6, 6) AS strres, substr(vccol, -6, 6) AS vcres FROM substrtest ORDER BY vcres
- ----
- strres vcres
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- NULL NULL
- query TT colnames
- SELECT substr(strcol, -5, 4) AS strres, substr(vccol, -5, 4) AS vcres FROM substrtest ORDER BY vcres
- ----
- strres vcres
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- NULL NULL
- # for or start is zero
- query T colnames
- SELECT substr(vccol, 0) AS vcres FROM substrtest ORDER BY vcres
- ----
- vcres
- (empty)
- 54.94
- Mn
- manganese
- 爱不释手
- NULL
- query T colnames
- SELECT substr(vccol, 0, 3) AS vcres FROM substrtest ORDER BY vcres
- ----
- vcres
- (empty)
- 54
- Mn
- ma
- 爱不
- NULL
- query TT colnames
- SELECT substr(strcol, 0, 0) AS strres, substr(vccol, 0, 0) AS vcres FROM substrtest ORDER BY vcres
- ----
- strres vcres
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- NULL NULL
- query TT colnames
- SELECT substr(strcol, 3, 0) AS strres, substr(vccol, 3, 0) AS vcres FROM substrtest ORDER BY vcres
- ----
- strres vcres
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- (empty) (empty)
- NULL NULL
- # NULL inputs
- query T
- SELECT substr(NULL, 1)
- ----
- NULL
- query T
- SELECT substr(NULL, 1, 3)
- ----
- NULL
- query T
- SELECT substr('text string', NULL)
- ----
- NULL
- query T
- SELECT substr(NULL, NULL)
- ----
- NULL
- query T
- SELECT substr('foo', NULL, 3)
- ----
- NULL
- query T
- SELECT substr('bar', NULL, NULL)
- ----
- NULL
- query T
- SELECT substr('baz', 2, NULL)
- ----
- NULL
- query T
- SELECT substr(NULL, NULL, NULL)
- ----
- NULL
- # alternative syntax
- query T colnames
- SELECT substring(vccol, 1, 3) AS vcres FROM substrtest ORDER BY vcres
- ----
- vcres
- (empty)
- 54.
- Mn
- man
- 爱不释
- NULL
- # testing different kinds of int columns and NULL content in columns
- query T
- SELECT substr(vccol, smicol, smicol) AS vcres FROM substrtest WHERE smicol > -1 ORDER BY vcres
- ----
- 4.
- M
- nga
- NULL
- query error negative substring length not allowed
- SELECT substr(vccol, smicol, smicol) AS vcres FROM substrtest ORDER BY vcres
- query T
- SELECT substr(vccol, intcol, intcol) AS vcres FROM substrtest ORDER BY vcres
- ----
- (empty)
- .94
- M
- 不释
- NULL
- NULL
- query T
- SELECT substr(vccol, smicol, intcol) AS vcres FROM substrtest ORDER BY vcres
- ----
- (empty)
- 4.9
- M
- NULL
- NULL
- NULL
- query T
- SELECT substr(vccol, intcol, smicol) AS vcres FROM substrtest WHERE smicol > -1 ORDER BY vcres
- ----
- .9
- M
- NULL
- NULL
- query T
- SELECT substr('subexpression test', ascii(''), 3)
- ----
- su
- # testing large numbers
- query T
- SELECT substr('abcdef', 2, 2147483647);
- ----
- bcdef
- query T
- SELECT substr('abcdef', 2147483647, 2);
- ----
- (empty)
- query T
- SELECT substr('abcdef', 2147483647, 2147483647);
- ----
- (empty)
- # substring alternate syntax
- query T
- SELECT substring('abcdef' from 2)
- ----
- bcdef
- query T
- SELECT substring('abcdef', 0, 3)
- ----
- ab
- query T
- SELECT substring('abcdef', 1, 3)
- ----
- abc
- query T
- SELECT substring('abcdef' for 3)
- ----
- abc
- query T
- SELECT substring('abcdef', 3, 3);
- ----
- cde
- query T
- SELECT substring('abcdef' from 3 for 3);
- ----
- cde
- # alternate syntax does not apply to substr
- statement error
- SELECT substr('abcdef' from 2)
- statement error
- SELECT substr('abcdef' for 3)
- statement error
- SELECT substr('abcdef' from 3 for 3)
- # alternate syntax edge cases
- query T
- SELECT substring('abcdef' from -1);
- ----
- abcdef
- query T
- SELECT substring('abcdef' from 2 for 2147483647);
- ----
- bcdef
- query T
- SELECT substring('abcdef' from 2147483647 for 2);
- ----
- (empty)
- query T
- SELECT substring('abcdef' from 2147483647 for 2147483647);
- ----
- (empty)
- query T
- SELECT substring('abcdef' for 2147483647);
- ----
- abcdef
- statement error
- SELECT substring('abcdef' for -1)
- query T
- SELECT substring('abcdef' from -1);
- ----
- abcdef
- query T
- SELECT substring('abcdef' from -1 for 3);
- ----
- a
- ### length ###
- statement ok
- CREATE TABLE lengthtest(strcol char(15), vccol varchar(15))
- statement ok
- INSERT INTO lengthtest VALUES
- ('str', 'str'), (' str', ' str'), ('str ', 'str '), ('你好', '你好'),
- ('今日は', '今日は'), ('हेलो', 'हेलो'),
- (NULL, NULL), ('', '')
- # invalid input
- statement error
- SELECT length(99)
- statement error
- SELECT length('str', 99)
- # standard tests
- query I rowsort
- SELECT octet_length(strcol) FROM lengthtest
- ----
- 15
- 15
- 15
- 15
- 19
- 21
- 23
- NULL
- query I rowsort
- SELECT length(vccol) FROM lengthtest
- ----
- 0
- 2
- 3
- 3
- 4
- 4
- 4
- NULL
- query I
- SELECT length('你好', 'big5')
- ----
- 3
- query I
- SELECT length('你好', 'iso-8859-5')
- ----
- 6
- query I
- SELECT octet_length('你好');
- ----
- 6
- query I
- SELECT bit_length('你好');
- ----
- 48
- # encoding name conversion FROM pg to WHATWG
- query I
- SELECT length('你好', 'ISO_8859_5')
- ----
- 6
- query error invalid encoding name 'iso-123'
- SELECT length('你好', 'iso-123')
- # NULL inputs
- query I
- SELECT length(NULL)
- ----
- NULL
- query I
- SELECT length('str', NULL)
- ----
- NULL
- query T
- SELECT replace('one', 'one', 'two')
- ----
- two
- query T
- SELECT replace('in a longer string', 'longer', 'shorter')
- ----
- in a shorter string
- query T
- SELECT 'hello'::bytea::text
- ----
- \x68656c6c6f
- ### concat ###
- query T
- SELECT concat('CONCAT', 'function')
- ----
- CONCATfunction
- query T
- SELECT concat('CONCAT', ' ', 'function')
- ----
- CONCAT function
- query T
- SELECT concat('CONCAT', NULL , 'function')
- ----
- CONCATfunction
- query I
- SELECT length(concat(''))
- ----
- 0
- query I
- SELECT length(concat(NULL))
- ----
- 0
- query I
- SELECT length(concat(' '))
- ----
- 1
- query T
- SELECT concat('CONCAT', 3 , 'function')
- ----
- CONCAT3function
- query T
- SELECT concat('CONCAT', length('abc') , 'function')
- ----
- CONCAT3function
- query T
- SELECT concat(3.32::float)
- ----
- 3.32
- query T
- SELECT concat(3.32::double precision)
- ----
- 3.32
- query T
- SELECT concat(3.32::int)
- ----
- 3
- query T
- SELECT concat(3.32)
- ----
- 3.32
- query T
- SELECT concat(3.32::decimal, 3)
- ----
- 3.323
- query T
- SELECT concat(3.32::float, 3)
- ----
- 3.323
- query T
- SELECT concat(3.32::float, '3')
- ----
- 3.323
- query T
- SELECT concat(true, false, 'function')
- ----
- tffunction
- query T
- SELECT concat('你好')
- ----
- 你好
- query T
- SELECT 'CONCAT' || 'operator'
- ----
- CONCAToperator
- query T
- SELECT 'CONCAT' || ' ' || 'operator'
- ----
- CONCAT operator
- query T
- SELECT 'CONCAT' || NULL
- ----
- NULL
- query T
- SELECT NULL || 'CONCAT'
- ----
- NULL
- query I
- SELECT length('' || '')
- ----
- 0
- query I
- SELECT length(NULL || NULL)
- ----
- NULL
- query I
- SELECT length(' ' || ' ')
- ----
- 2
- query T
- SELECT 'CONCAT' || 3 || 'operator'
- ----
- CONCAT3operator
- query T
- SELECT 'CONCAT' || length('abc') || 'operator'
- ----
- CONCAT3operator
- query T
- SELECT '' || true || false
- ----
- truefalse
- query T
- SELECT '你' || '好'
- ----
- 你好
- query error db error: ERROR: operator does not exist: boolean \|\| boolean
- SELECT true || false
- # concat_ws
- query error db error: ERROR: function concat_ws\(\) does not exist
- SELECT concat_ws();
- query error db error: ERROR: function concat_ws\(unknown\) does not exist
- SELECT concat_ws('a');
- query T
- SELECT concat_ws('', 'a', 'b') AS word;
- ----
- ab
- query T
- SELECT concat_ws(E'\t', 'S', 'M', 'T');
- ----
- S M T
- query T
- SELECT concat_ws(', ', interval '1d', 1.23::numeric, 4.56::float);
- ----
- 1 day, 1.23, 4.56
- query T
- SELECT concat_ws(', ', interval '1d', null, 1.23::numeric, null, 4.57::float);
- ----
- 1 day, 1.23, 4.57
- query T
- SELECT concat_ws(', ', interval '1d', null, 1.23::numeric, null, 4.57::float, null);
- ----
- 1 day, 1.23, 4.57
- query T
- SELECT concat_ws(null, interval '1d', null, 1.23::numeric, null, 4.57::float, null);
- ----
- NULL
- query T
- SELECT concat_ws(null, null);
- ----
- NULL
- query T
- SELECT concat_ws('x', null);
- ----
- (empty)
- query T
- SELECT split_part('abc~@~def~@~ghi', '~@~', 2)
- ----
- def
- query T
- SELECT split_part('abc~@~def~@~ghi', '', 1)
- ----
- abc~@~def~@~ghi
- query T
- SELECT split_part('abc~@~def~@~ghi', '~@~', 4)
- ----
- (empty)
- query T
- SELECT split_part('hello there', '', 1)
- ----
- hello there
- query T
- SELECT split_part('', 'not', 1)
- ----
- (empty)
- query error field position must be greater than zero
- SELECT split_part('abc~@~def~@~ghi', '~@~', 0)
- query error db error: ERROR: function split_part\(\) does not exist
- SELECT split_part()
- query error db error: ERROR: function split_part\(unknown, unknown\) does not exist
- SELECT split_part('one', 'two')
- query error db error: ERROR: function split_part\(integer, integer, integer\) does not exist
- SELECT split_part(1, 2, 3)
- ### lpad ###
- query T
- SELECT lpad('str', 42, 'pad')
- ----
- padpadpadpadpadpadpadpadpadpadpadpadpadstr
- query T
- SELECT lpad('str', 4, 'pad')
- ----
- pstr
- query T
- SELECT lpad('str', 5, 'pad')
- ----
- pastr
- query T
- SELECT REPLACE(lpad('str', 5), ' ', '_')
- ----
- __str
- query T
- SELECT lpad('str', 7, 'pad')
- ----
- padpstr
- query T
- SELECT lpad('str', 3, 'pad')
- ----
- str
- query T
- SELECT lpad('str', 2, 'pad')
- ----
- st
- query T
- SELECT lpad('str', 1, 'pad')
- ----
- s
- statement error
- SELECT lpad('str', -1, 'pad')
- query T
- SELECT lpad('str', 0, 'pad')
- ----
- (empty)
- query T
- SELECT lpad('str', NULL, 'pad')
- ----
- NULL
- query T
- SELECT lpad(NULL, 10, 'pad')
- ----
- NULL
- query T
- SELECT lpad(NULL, 10, NULL)
- ----
- NULL
- query T
- SELECT lpad('str', 10, NULL)
- ----
- NULL
- query T
- SELECT lpad('str', 10, '')
- ----
- str
- query T
- SELECT lpad('', 10, '')
- ----
- (empty)
- query T
- SELECT lpad('', 10, 'pad')
- ----
- padpadpadp
- query T
- SELECT lpad('đẹp', 1, 'pad')
- ----
- đ
- query T
- SELECT lpad('str', 5, 'đẹp')
- ----
- đẹstr
- query error requested length too large
- SELECT lpad('', 2147483647)
- ### ilike ###
- # ILIKE tests lifted from Cockroach
- query B
- SELECT 'TEST' ILIKE 'TEST'
- ----
- true
- query B
- SELECT 'TEST' ILIKE 'test'
- ----
- true
- query B
- SELECT 'TEST' ILIKE 'TE%'
- ----
- true
- query B
- SELECT 'TEST' ILIKE '%E%'
- ----
- true
- query B
- SELECT 'TEST' ILIKE '%e%'
- ----
- true
- query B
- SELECT 'TEST' ILIKE 'TES_'
- ----
- true
- query B
- SELECT 'TEST' ILIKE 'TE_%'
- ----
- true
- query B
- SELECT 'TEST' ILIKE 'TE_'
- ----
- false
- query B
- SELECT 'TEST' ILIKE '%'
- ----
- true
- query B
- SELECT 'TEST' ILIKE '%R'
- ----
- false
- query B
- SELECT 'TEST' ILIKE 'TESTER'
- ----
- false
- query B
- SELECT 'TEST' ILIKE 'tester'
- ----
- false
- query B
- SELECT 'TEST' ILIKE ''
- ----
- false
- query B
- SELECT '' ILIKE ''
- ----
- true
- query B
- SELECT 'T' ILIKE '_'
- ----
- true
- query B
- SELECT 'TE' ILIKE '_'
- ----
- false
- query B
- SELECT 'TEST' NOT ILIKE '%E%'
- ----
- false
- query B
- SELECT 'TEST' NOT ILIKE 'TES_'
- ----
- false
- query B
- SELECT 'TEST' NOT ILIKE 'TeS_'
- ----
- false
- query B
- SELECT 'TEST' NOT ILIKE 'TE_'
- ----
- true
- # Invalid type mods
- query error length for type character varying must be between 1 and 10485760
- SELECT ''::VARCHAR(0)
- query error length for type character varying must be between 1 and 10485760
- SELECT ''::VARCHAR(10485761)
- query error length for type character must be between 1 and 10485760
- SELECT ''::CHAR(0)
- query error length for type character must be between 1 and 10485760
- SELECT ''::CHAR(10485761)
- query error length for type character varying must be between 1 and 10485760
- SELECT ''::pg_catalog.VARCHAR(0)
- query error length for type character varying must be between 1 and 10485760
- SELECT ''::pg_catalog.VARCHAR(10485761)
- query error length for type character must be between 1 and 10485760
- SELECT ''::pg_catalog.bpchar(0)
- query error length for type character must be between 1 and 10485760
- SELECT ''::pg_catalog.bpchar(10485761)
- ### position ###
- statement ok
- CREATE TABLE positiontest (strcol1 char(15), strcol2 char(15), vccol1 varchar(15), vccol2 varchar(15))
- statement ok
- INSERT INTO positiontest VALUES ('om', 'Thomas', 'om', 'Thomas'), ('foo', 'barbar', 'foo', 'barbar'),
- (NULL, 'str', NULL, 'str'), ('str', NULL, 'str', NULL), ('释手', '爱不释手', '释手', '爱不释手'),
- ('', 'str', '', 'str'), ('str', '', 'str', '')
- # invalid input
- statement error Expected IN, found right parenthesis
- SELECT position(42)
- statement error Expected IN, found right parenthesis
- SELECT position('str')
- statement error db error: ERROR: function position\(integer, unknown\) does not exist
- SELECT position(42 IN 'str')
- statement error db error: ERROR: function position\(unknown, integer\) does not exist
- SELECT position('str' IN 42)
- statement error Expected right parenthesis, found comma
- SELECT position('str' IN 42, 172)
- # standard tests
- query I rowsort
- select position(strcol1 IN strcol2) from positiontest;
- ----
- 0
- 0
- 1
- 3
- 3
- NULL
- NULL
- query I rowsort
- SELECT position(vccol1 IN vccol2) FROM positiontest
- ----
- 3
- 0
- NULL
- NULL
- 3
- 1
- 0
- # NULL inputs
- query I
- SELECT position(NULL IN 'str')
- ----
- NULL
- query I
- SELECT position('str' IN NULL)
- ----
- NULL
- # combining characters
- query I
- SELECT position('ः॑' IN 'रः॑')
- ----
- 2
- # this is exactly the same as above, but using unicode escapes
- query I
- SELECT position(e'\u0903\u0951' IN e'\u0930\u0903\u0951')
- ----
- 2
- ### left ###
- statement ok
- CREATE TABLE lefttest (strcol char(15), vccol varchar(15), smicol smallint, intcol int)
- statement ok
- INSERT INTO lefttest VALUES ('Mg', 'Mn', 1, -1), ('magnesium', 'manganese', 3, NULL),
- (NULL, NULL, 0, 0), ('24.31', '54.94', 3, -3), ('长久不见', '爱不释手', NULL, 3),
- ('', '', -1, 2)
- # invalid input
- statement error
- SELECT left(42)
- statement error
- SELECT left('str')
- statement error
- SELECT left(42, 'str')
- statement error
- SELECT left('str', 42, 17)
- # standard tests
- query T rowsort
- select left(strcol, 3) from lefttest
- ----
- (empty)
- 24.
- Mg
- NULL
- mag
- 长久不
- # edge case
- query T rowsort
- SELECT left(vccol, 0) FROM lefttest
- ----
- (empty)
- (empty)
- NULL
- (empty)
- (empty)
- (empty)
- # from the front
- query T rowsort
- SELECT left(vccol, 2) FROM lefttest
- ----
- Mn
- ma
- NULL
- 54
- 爱不
- (empty)
- # from the back
- query T rowsort
- SELECT left(vccol, -2) FROM lefttest
- ----
- (empty)
- mangane
- NULL
- 54.
- 爱不
- (empty)
- query TT rowsort
- SELECT left(vccol, smicol), left(vccol, intcol) FROM lefttest
- ----
- M M
- man NULL
- NULL NULL
- 54. 54
- NULL 爱不释
- (empty) (empty)
- # NULL inputs
- query T
- SELECT left(NULL, 99)
- ----
- NULL
- query T
- SELECT left('str', NULL)
- ----
- NULL
- # combining characters
- query T
- SELECT left('रः॑', 0)
- ----
- (empty)
- query T
- SELECT left('रः॑', 1)
- ----
- र
- query T
- SELECT left('रः॑', -1)
- ----
- रः
- # this is exactly the same as above, but using unicode escapes
- query T
- SELECT left(e'\u0930\u0903\u0951', -1)
- ----
- रः
- # integer edge cases
- # i32:MIN
- query T
- SELECT left('hello', -2147483648)
- ----
- (empty)
- # i32:MIN + 1
- query T
- SELECT left('hello', -2147483647)
- ----
- (empty)
- # i64
- query error db error: ERROR: function left\(unknown, bigint\) does not exist
- SELECT left('hello', 2147483648)
- ### right ###
- statement ok
- CREATE TABLE righttest (strcol char(15), vccol varchar(15), smicol smallint, intcol int)
- statement ok
- INSERT INTO righttest VALUES ('Mg', 'Mn', 1, -1), ('magnesium', 'manganese', 3, NULL),
- (NULL, NULL, 0, 0), ('24.31', '54.94', 3, -3), ('长久不见', '爱不释手', NULL, 3),
- ('', '', -1, 2)
- # invalid input
- statement error
- SELECT right(42)
- statement error
- SELECT right('str')
- statement error
- SELECT right(42, 'str')
- statement error
- SELECT right('str', 42, 17)
- # standard tests
- query T rowsort
- select right(strcol, 3) from righttest
- ----
- (empty)
- .31
- Mg
- NULL
- ium
- 久不见
- # edge case
- query T rowsort
- SELECT right(vccol, 0) FROM righttest
- ----
- (empty)
- (empty)
- NULL
- (empty)
- (empty)
- (empty)
- # from the back
- query T rowsort
- SELECT right(vccol, 2) FROM righttest
- ----
- Mn
- se
- NULL
- 94
- 释手
- (empty)
- # from the front
- query T rowsort
- SELECT right(vccol, -2) FROM righttest
- ----
- (empty)
- nganese
- NULL
- .94
- 释手
- (empty)
- query TT rowsort
- SELECT right(vccol, smicol), right(vccol, intcol) FROM righttest
- ----
- n n
- ese NULL
- NULL NULL
- .94 94
- NULL 不释手
- (empty) (empty)
- # NULL inputs
- query T
- SELECT right(NULL, 99)
- ----
- NULL
- query T
- SELECT right('str', NULL)
- ----
- NULL
- # combining characters
- query T
- SELECT right('रः॑', 0)
- ----
- (empty)
- query T
- SELECT right('रः॑', 1)
- ----
- ॑
- query T
- SELECT right('रः॑', -1)
- ----
- ः॑
- # this is exactly the same as above, but using unicode escapes
- query T
- SELECT right(e'\u0930\u0903\u0951', -1)
- ----
- ः॑
- # integer edge cases
- # i32:MIN, this seems strange, but it's what Postgres does
- query T
- SELECT right('hello', -2147483648)
- ----
- hello
- # i32:MIN + 1
- query T
- SELECT right('hello', -2147483647)
- ----
- (empty)
- # i64
- query error db error: ERROR: function right\(unknown, bigint\) does not exist
- SELECT right('hello', 2147483648)
- query T
- SELECT repeat('hi', 5)
- ----
- hihihihihi
- query T
- SELECT repeat('a', 0)
- ----
- (empty)
- query T
- SELECT repeat('a', -1)
- ----
- (empty)
- query error requested length too large
- SELECT repeat('a', 2147483647)
- # Check for char cmp validity, which ignores white space
- # ...at datum level
- statement ok
- CREATE TABLE bpchar_t (a char(5));
- statement ok
- INSERT INTO bpchar_t VALUES ('a');
- query TTTTTT
- SELECT a = 'a ', a != 'a ', 'a ' < a, 'a ' <= a, a > 'a ', a >= 'a ' FROM bpchar_t;
- ----
- true false false true false true
- # ...at row level
- statement ok
- INSERT INTO bpchar_t VALUES ('a ');
- query T
- SELECT DISTINCT octet_length(a) FROM bpchar_t;
- ----
- 5
- # LIKE comparisons using char retains lhs padding, but rhs is cast to string, so
- # trimmed.
- query B
- SELECT 'abc'::char(3) ~~ 'abc';
- ----
- true
- query B
- SELECT 'abc'::char(3) ~~ 'abc ';
- ----
- false
- query B
- SELECT 'abc'::char(3) ~~ 'abc'::char(4);
- ----
- true
- query B
- SELECT 'abc'::char(4) ~~ 'abc';
- ----
- false
- query B
- SELECT 'abc'::char(4) ~~ 'abc ';
- ----
- true
- query B
- SELECT 'abc'::char(4) ~~ 'abc'::char(3);
- ----
- false
- query B
- SELECT 'abc'::char(4) ~~ 'abc'::char(4);
- ----
- false
- query B
- SELECT 'abc'::char(3) ~~ 'abc'::char(4);
- ----
- true
- query B
- SELECT 'abc'::char(3) !~~* 'Abc'::char(4);
- ----
- false
- query B
- SELECT 'abc'::char(3) NOT ILIKE 'Abc'::char(4);
- ----
- false
- query B
- SELECT 'abc'::char(3) !~ 'Abc'::char(4);
- ----
- true
- # Regression for https://github.com/MaterializeInc/materialize/pull/7522#issuecomment-893343138
- query T
- SELECT 'a'::char(3) = 'a '::varchar(3);
- ----
- true
- # Regression for https://github.com/MaterializeInc/materialize/pull/7522#issuecomment-895061714
- statement ok
- CREATE TABLE char_col (a char(10));
- statement ok
- INSERT INTO char_col VALUES ('a'), ('bc'), ('def');
- query T
- SELECT max(a)::text FROM char_col
- ----
- def
- query I
- SELECT octet_length(max(a)) FROM char_col
- ----
- 10
- # Ensure calls to Any param'ed funcs pad char values
- query T
- SELECT to_jsonb('a'::char(10))
- ----
- "a "
- # Regression for https://github.com/MaterializeInc/materialize/pull/7522#issuecomment-895057022
- query T
- SELECT CONCAT('a'::char(3), 'b'::text, 'c');
- ----
- a bc
- query T
- SELECT CONCAT('a'::text, 'b'::char(3), 'c');
- ----
- ab c
- # Regression for https://github.com/MaterializeInc/database-issues/issues/5304
- statement ok
- CREATE TABLE gh18095_0(c0 VARCHAR(55))
- statement ok
- CREATE TABLE gh18095_1(c0 CHAR(96));
- statement ok
- INSERT INTO gh18095_1 VALUES('''%ꆔA?')
- query T
- SELECT FROM gh18095_1 JOIN gh18095_0 ON (gh18095_1.c0)LIKE((gh18095_1.c0)::VARCHAR(4));
- ----
- ### translate ###
- # NULL inputs
- query I
- SELECT translate(NULL, 'one', 'two')
- ----
- NULL
- query I
- SELECT translate('one', NULL, 'two')
- ----
- NULL
- query I
- SELECT translate('one', 'two', NULL)
- ----
- NULL
- query I
- SELECT translate('one', NULL, NULL)
- ----
- NULL
- query I
- SELECT translate(NULL, 'one', NULL)
- ----
- NULL
- query I
- SELECT translate(NULL, NULL, 'one')
- ----
- NULL
- query I
- SELECT translate(NULL, NULL, NULL)
- ----
- NULL
- # replace single occurrence of a single char
- query T
- SELECT translate('foe', 'f', 't')
- ----
- toe
- # replace multiple occurrences of a single char
- query T
- SELECT translate('hello', 'l', 'x')
- ----
- hexxo
- # remove extra occurrences when len(from) > len(to)
- query T
- SELECT translate('ffl', 'fl', 't')
- ----
- tt
- query I
- SELECT translate('[1]', '[]', '')::numeric
- ----
- 1
- # ignore extra occurences when len(to) > len(from)
- query T
- SELECT translate('something', 'sth', 'xfvlg')
- ----
- xomefving
- # ignore non-matching extra occurrences
- query T
- SELECT translate('ffl', 'fx', 't')
- ----
- ttl
- query T
- SELECT translate('hello', 'fl', 'tx')
- ----
- hexxo
- query T
- SELECT translate('12345', '143', 'ax')
- ----
- a2x5
- query T
- SELECT translate('a', '👋a', E'xy')
- ----
- y
- # constant_time_eq for string
- statement ok
- CREATE TABLE test_constant_time_eq (ord integer, str1 text, str2 text);
- statement ok
- INSERT INTO test_constant_time_eq VALUES
- (1, NULL, NULL),
- (2, NULL, ''),
- (3, '', ''),
- (4, '', ' '),
- (5, NULL, 'abc'),
- (6, 'abc', 'abc'),
- (7, 'abc', 'abcd'),
- (8, 'abcd', 'abc'),
- (9, 'ABC', 'abc'),
- (10, ' abc', 'abc'),
- (11, '\t\n3@\u0930\u0930', '\t\n3@\u0930\u0930'),
- (12, '.*', 'aa');
- query B
- SELECT constant_time_eq(str1, str2) FROM test_constant_time_eq ORDER BY ord;
- ----
- NULL
- NULL
- true
- false
- NULL
- true
- false
- false
- false
- false
- true
- false
- query I
- SELECT count(*) FROM test_constant_time_eq WHERE constant_time_eq(str1, str2) <> (str1 = str2);
- ----
- 0
- ## initcap
- query T
- SELECT initcap('hi THOMAS')
- ----
- Hi Thomas
- query I
- SELECT length(initcap(''))
- ----
- 0
- query T
- SELECT initcap('a')
- ----
- A
- query T
- SELECT initcap('a,b,c')
- ----
- A,B,C
- query T
- SELECT initcap('a18z')
- ----
- A18z
- query T
- SELECT initcap('ABC')
- ----
- Abc
- query T
- SELECT initcap('Let''s go')
- ----
- Let'S Go
- query T
- SELECT starts_with('abc', 'ab')
- ----
- true
- query T
- SELECT starts_with('abc', 'ba')
- ----
- false
- query T
- SELECT starts_with('abc', '')
- ----
- true
- query T
- SELECT starts_with('abc', NULL)
- ----
- NULL
- query T
- SELECT starts_with('abc', '%')
- ----
- false
- query T
- SELECT starts_with(NULL, NULL)
- ----
- NULL
- query T
- SELECT starts_with(NULL, 'ab')
- ----
- NULL
- # reverse for string
- statement ok
- create table words (word text);
- statement ok
- insert into words values ('hello'), ('world'), ('!');
- query T
- select reverse(word) from words;
- ----
- !
- dlrow
- olleh
- # string_to_array - begin.
- statement ok
- create table string_to_array_words (word text);
- statement ok
- insert into string_to_array_words values ('hello world');
- # string_to_array - NULL delimiter and null_string not set.
- query T
- select string_to_array(word, NULL) from string_to_array_words;
- ----
- {h,e,l,l,o," ",w,o,r,l,d}
- # string_to_array - empty string delimiter and null_string not set.
- query T
- select string_to_array(word, '') from string_to_array_words;
- ----
- {"hello world"}
- # string_to_array - white space delimiter and null_string not set.
- query T
- select string_to_array(word, ' ') from string_to_array_words;
- ----
- {hello,world}
- # string_to_array - white space delimiter and null_string set to first word in results.
- query T
- select string_to_array(word, ' ', 'hello') from string_to_array_words;
- ----
- {NULL,world}
- # string_to_array - empty string delimiter and null_string set to whole word.
- # expectation: null_string is ignored if no delimiter is passed.
- query T
- select string_to_array(word, '', 'hello world') from string_to_array_words;
- ----
- {"hello world"}
- # string_to_array - white space delimiter and null_string set to NULL.
- query T
- select string_to_array(word, ' ', NULL) from string_to_array_words;
- ----
- {hello,world}
- # string_to_array - first word delimiter and null_string not set.
- # expectation: delimiter should convert a full match to empty string.
- query T
- select string_to_array(word, 'hello') from string_to_array_words;
- ----
- {""," world"}
- # string_to_array - empty string must return an empty array.
- query T
- select string_to_array('', 'hello') from string_to_array_words;
- ----
- {}
- query T
- select string_to_array('', '') from string_to_array_words;
- ----
- {}
- # string_to_array - whitespace.
- query T
- select string_to_array(' ', '') from string_to_array_words;
- ----
- {" "}
- # string_to_array - null input results in null.
- query T
- select string_to_array(null, '') from string_to_array_words;
- ----
- NULL
- # string_to_array - non string input results in error.
- query error
- select string_to_array('hello world', 0) from string_to_array_words;
- # string_to_array - end.
|