-1

I need your help, I am a new user in postgresSQL.

I only have the first column, need to get the second one

like this-->

Column A Column B
URVKK/GPA/nGPA/...GPA. URVKK_GPA_GPA_GPA
URVKK2935874GPA URVKK_GPA
URVKK2935874ControlGPA5732 URVKK_GPA

I have no idea other than case, maybe you can help me with an idea, thanks

I will be very grateful for help

Alex
  • 1
  • 2
  • You should really start with a basic SQL tutorial, rather than expecting people to teach you the very basics on this site. – treuss Nov 09 '22 at 13:12
  • @treuss i know a basic sql, i don't know how best to automate queries with postgres in qlik sense – Alex Nov 09 '22 at 16:14

1 Answers1

0

Are you trying to achieve this using SQL or Qlik script? Also, how would you verbalize what you're trying to do? Do all of the [Column A] values start with "URVKK" or are you needing to pattern match that in a more specific way? And after that starting pattern, are you just trying to replace anything that isn't "GPA" with an underscore?

If you're trying to achieve this with Qlik script, you could use this expression based on the little information I have here:
if(left([Column A], 5) = 'URVKK', 'URVKK' & Repeat('_GPA', SubStringCount([Column A], 'GPA')))

If it's SQL you're wanting to use and you're using PostgreSQL 15+, you could do something like:
CASE WHEN left("Column A", 5) = 'URVKK' THEN 'URVKK' || repeat('_GPA', regexp_count("Column A", '(GPA)')) ELSE "Column A" END

If you're trying to use SQL and wanting to specifically use Regex in this case, that's going to be a lot harder just because it's not easy to use Regex to do something like "match all substring characters unless the substring matches 'GPA'."

SmoothBrane
  • 721
  • 4
  • 5