Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

366
Views
In Postgres, running ANALYZE changes behaviour of ILIKE clause with COLLATE

We are migrating an application from SQL Server to Postgres and attempting to emulate various aspects of the case insensitivity of SQL Server. We have created a non-deterministic collation to support case-insensitive matching of foreign keys and equality comparisons.

But we are seeing some weird behaviour when using ILIKE which we can't explain, and would appreciate some assistance.

To see the behaviour, run the following on a fresh database:

CREATE COLLATION IF NOT EXISTS public.ci (provider = icu, locale = 'und-u-ks-level2', deterministic = false);

DROP TABLE IF EXISTS sort_test;

CREATE TABLE sort_test (a text COLLATE public.ci);

INSERT INTO sort_test SELECT md5(n::text) FROM generate_series(1, 10000) n;

-- Removing the following line fixes the issue
ANALYZE sort_test;

-- This line throws "nondeterministic collations are not supported for ILIKE"
SELECT * FROM sort_test WHERE a ILIKE 'c4ca4238a0%' COLLATE "und-x-icu";

Why does running the ANALYZE statement break the ILIKE statement?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

That behavior is a PostgreSQL bug.

The reason why it works without the ANALYZE is that the error is thrown when applying the operator to the “histogram bounds” in the statistics. Before ANALYZE there are no statistics, so no error is thrown.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!