mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Clean up parsing of ltree and lquery some more.
Fix lquery parsing to handle repeated flag characters correctly, and to enforce the max label length correctly in some cases where it did not before, and to detect empty labels in some cases where it did not before. In a more cosmetic vein, use a switch rather than if-then chains to handle the different states, and avoid unnecessary checks on charlen when looking for ASCII characters, and factor out multiple copies of the label length checking code. Tom Lane and Dmitry Belyavsky Discussion: https://postgr.es/m/CADqLbzLVkBuPX0812o+z=c3i6honszsZZ6VQOSKR3VPbB56P3w@mail.gmail.com
This commit is contained in:
@ -10,6 +10,14 @@ SELECT '1'::ltree;
|
||||
SELECT '1.2'::ltree;
|
||||
SELECT '1.2._3'::ltree;
|
||||
|
||||
-- empty labels not allowed
|
||||
SELECT '.2.3'::ltree;
|
||||
SELECT '1..3'::ltree;
|
||||
SELECT '1.2.'::ltree;
|
||||
|
||||
SELECT repeat('x', 255)::ltree;
|
||||
SELECT repeat('x', 256)::ltree;
|
||||
|
||||
SELECT ltree2text('1.2.3.34.sdf');
|
||||
SELECT text2ltree('1.2.3.34.sdf');
|
||||
|
||||
@ -88,8 +96,26 @@ SELECT '1.*.4|3|2.*{,4}'::lquery;
|
||||
SELECT '1.*.4|3|2.*{1,}'::lquery;
|
||||
SELECT '1.*.4|3|2.*{1}'::lquery;
|
||||
SELECT 'foo.bar{,}.!a*|b{1,}.c{,44}.d{3,4}'::lquery;
|
||||
SELECT 'foo*@@*'::lquery;
|
||||
SELECT 'qwerty%@*.tu'::lquery;
|
||||
|
||||
-- empty labels not allowed
|
||||
SELECT '.2.3'::lquery;
|
||||
SELECT '1..3'::lquery;
|
||||
SELECT '1.2.'::lquery;
|
||||
SELECT '@.2.3'::lquery;
|
||||
SELECT '1.@.3'::lquery;
|
||||
SELECT '1.2.@'::lquery;
|
||||
SELECT '!.2.3'::lquery;
|
||||
SELECT '1.!.3'::lquery;
|
||||
SELECT '1.2.!'::lquery;
|
||||
SELECT '1.2.3|@.4'::lquery;
|
||||
|
||||
SELECT (repeat('x', 255) || '*@@*')::lquery;
|
||||
SELECT (repeat('x', 256) || '*@@*')::lquery;
|
||||
SELECT ('!' || repeat('x', 255))::lquery;
|
||||
SELECT ('!' || repeat('x', 256))::lquery;
|
||||
|
||||
SELECT nlevel('1.2.3.4');
|
||||
SELECT nlevel(('1' || repeat('.1', 65534))::ltree);
|
||||
SELECT nlevel(('1' || repeat('.1', 65535))::ltree);
|
||||
@ -200,6 +226,7 @@ SELECT 'a.b.c.d.e'::ltree ~ '!c{0,3}.!a{2,}';
|
||||
SELECT 'a.b.c.d.e'::ltree ~ '!c{0,3}.!d{2,}.*';
|
||||
|
||||
SELECT 'QWER_TY'::ltree ~ 'q%@*';
|
||||
SELECT 'QWER_TY'::ltree ~ 'q%@*%@*';
|
||||
SELECT 'QWER_TY'::ltree ~ 'Q_t%@*';
|
||||
SELECT 'QWER_GY'::ltree ~ 'q_t%@*';
|
||||
|
||||
|
Reference in New Issue
Block a user