Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

73
Visualizações
Optimising IF-THEN-ELSE in trigger

I have a trigger which needs to make a match on a phone number, so far this works, but it seems rather not optimised:

IF NEW.caller LIKE '44%' THEN
    caller_tmp := SUBSTRING(NEW.caller FROM 3);
    IF caller_tmp ~ '^[0-9]+$' THEN
        NEW.caller_name := (SELECT phonenumber_name FROM phonebook WHERE caller_tmp::BIGINT LIMIT 1);
    END IF;
ELSEIF NEW.caller LIKE '+44%' THEN
    caller_tmp := SUBSTRING(NEW.caller FROM 4);
    IF caller_tmp ~ '^[0-9]+$' THEN
        NEW.caller_name := (SELECT phonenumber_name FROM phonebook WHERE caller_tmp::BIGINT LIMIT 1);
    END IF;
ELSEIF NEW.caller LIKE '0044%' THEN
    caller_tmp := SUBSTRING(NEW.caller FROM 5);
    IF caller_tmp ~ '^[0-9]+$' THEN
        NEW.caller_name := (SELECT phonenumber_name FROM phonebook WHERE caller_tmp::BIGINT LIMIT 1);
    END IF;
END IF;

I need to check if the phone number is from the UK with either containing 44, +44 or 0044 in the front. If it does, I need to check if it's a valid integer, and then do my matching.

Could this be optimised for better perfomance?

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda