I’m using Postgresql DB.
I want to perform a query against a numeric column in a table to find if the value starts with a particular number.
I currently have:
SELECT * FROM myTable WHERE to_char(ID, '12345678') LIKE '2%'
However this returns an empty dataset (but there are values in the ID column which start with 2.
Many thanks
Steve
Don’t laugh. As an alternative to the casts, you could use a range query, like:
This could cause postgres to generate a much better query plan, because an index can be used (if present, which can be expected for an id field)
UPDATE:
The query plans: