I came to a standtstill with a relatively trivial issue.
Such a simple query:
select distinct field_name,length(field_name) from table_a where
field_name similar to `2[0-9][0-9]%`;
returns the following rows:
field_name|length|
----------+------+
200 | 3|
203 | 3|
210 | 3|
But the very similar one, where only ‘%’ in the expression has been omitted returns no rows:
select distinct field_name,length(field_name) from table_a where
field_name similar to '[23][0-9][0-2]';
The field_name column is defined as CHAR(10).
The problem probably results from some characters at the end of the field but I don’t know how to eliminate them.
Would you mind telling me how to solve it?
Checked postgresql documentation and tutorials,
searched on google and stackoverflow wtihout success.
2
Answers
Just a quick guess: In the first query you are using the % Wildcard. So the char must not be exactly 3 digits long. Maybe there are some trailing spaces in your data?
Try something like that:
Let me know if that solves your issue.
fiddle