0

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

2
  • Please provide sample data, desired results, a clear explanation, and a database tag. Commented Jul 15, 2020 at 13:35
  • The like operator 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. Commented Jul 19, 2020 at 4:42

1 Answer 1

1

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.