pgsql/update_tables_0.5.x-0.6.pgsql
branchv0.6.x
changeset 512 821d3ffaaaca
parent 511 0244f1344b04
child 514 d863a44a6353
equal deleted inserted replaced
511:0244f1344b04 512:821d3ffaaaca
   472                AND address = localpart
   472                AND address = localpart
   473             LOOP
   473             LOOP
   474                 RETURN NEXT record;
   474                 RETURN NEXT record;
   475             END LOOP;
   475             END LOOP;
   476         IF NOT FOUND THEN
   476         IF NOT FOUND THEN
       
   477             -- First, we have to check existing mailboxes and
       
   478             -- return identity if one exists
   477             FOR record IN
   479             FOR record IN
   478                 SELECT recipient, destination
   480                 SELECT recipient, recipient as destination
   479                   FROM catchall
   481                   FROM users
   480                  WHERE gid = did
   482                  WHERE gid = did
       
   483                    AND local_part = localpart
       
   484                 UNION SELECT recipient, recipient as destination
       
   485                   FROM relocated
       
   486                  WHERE gid = did
       
   487                    AND address = localpart
   481                 LOOP
   488                 LOOP
   482                     RETURN NEXT record;
   489                     RETURN NEXT record;
   483                 END LOOP;
   490                 END LOOP;
       
   491             -- Only now can we think about catchalls...
       
   492             IF NOT FOUND THEN
       
   493                 FOR record IN
       
   494                     SELECT recipient, destination
       
   495                       FROM catchall
       
   496                     WHERE gid = did
       
   497                     LOOP
       
   498                         RETURN NEXT record;
       
   499                     END LOOP;
       
   500             END IF;
   484         END IF;
   501         END IF;
   485         RETURN;
   502         RETURN;
   486     END;
   503     END;
   487 $$ LANGUAGE plpgsql STABLE
   504 $$ LANGUAGE plpgsql STABLE
   488 RETURNS NULL ON NULL INPUT
   505 RETURNS NULL ON NULL INPUT