clear markdown feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3799136 fiddles created (41768 in the last week).

CREATE TABLE tbl(string text); INSERT INTO tbl(string) SELECT x FROM generate_series(1, 10000) x; CREATE INDEX tbl_string_text_pattern_idx ON tbl(string text_pattern_ops);
10000 rows affected
 hidden batch(es)


-- left anchored pattern can use index! EXPLAIN SELECT * FROM tbl WHERE string ~ '^1234';
QUERY PLAN
Bitmap Heap Scan on tbl (cost=4.80..52.64 rows=50 width=32)
Filter: (string ~ '^1234'::text)
-> Bitmap Index Scan on tbl_string_text_pattern_idx (cost=0.00..4.79 rows=50 width=0)
Index Cond: ((string ~>=~ '1234'::text) AND (string ~<~ '1235'::text))
 hidden batch(es)