Does anyone knows how to say if val1 = X/state/Amercia/LA/ or X/state/ the val2 = 'LA'.
code
when TRIM(val1) like '^X*/state/' or TRIM(val1) like '^X*/LA/' then 'LA'
Thank you
Given these results (please note I preserved the spelling of 'Amercia'):
select trim('X/state/Amercia/LA/') ~ '^X/state/($|Amercia/LA/$)';
?column?
----------
t
(1 row)
select trim('X/state/Amercia/LA/') ~ '^X/state/($|Amercia/LA/$)';
?column?
----------
t
(1 row)
select trim('X/state/') ~ '^X/state/($|Amercia/LA/$)';
?column?
----------
t
(1 row)
select trim('X/state/SomethingElse') ~ '^X/state/($|Amercia/LA/$)';
?column?
----------
f
(1 row)
select trim('Xother') ~ '^X/state/($|Amercia/LA/$)';
?column?
----------
f
(1 row)
select trim('X/state/Amercia/VA') ~ '^X/state/($|Amercia/LA/$)';
?column?
----------
f
(1 row)
Your when should be:
when trim(val1) ~ '^X/state/($|Amercia/LA/$)' then 'LA'
likeoperator does not accept any regular expression, but requires a PostgreSQL dialect. You can look it up here. Your best option is the official documentation on the subject.