003-view_organization_identification.sql 1.3 KB

1234567891011121314151617181920
  1. CREATE OR REPLACE VIEW view_organization_identification AS
  2. SELECT o.id, o.name, o.identifier, o.siretNumber, o.waldecNumber,
  3. a.streetAddress, a.streetAddressSecond, a.streetAddressThird, a.addressCity, a.postalCode,
  4. c.email, c.telphone,
  5. REGEXP_REPLACE(
  6. REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(LOWER(trim(o.name)), '[éèê]', 'e'), '[à]', 'a'), '[ç]', 'c'),
  7. '[^a-z0-9]+',
  8. '+'
  9. ) as normalizedName,
  10. REGEXP_REPLACE(
  11. LOWER(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(trim(concat(a.streetAddress, ' ', a.streetAddressSecond, ' ', a.streetAddressThird)), '[éèê]', 'e'), '[à]', 'a'), '[ç]', 'c')),
  12. '[^a-z0-9]+',
  13. '+'
  14. ) as normalizedAddress
  15. FROM opentalent.Organization o
  16. INNER JOIN opentalent.OrganizationAddressPostal oa ON oa.organization_id = o.id
  17. INNER JOIN opentalent.AddressPostal a ON a.id = oa.addressPostal_id
  18. INNER JOIN opentalent.organization_contactpoint oc ON oc.organization_id = o.id
  19. INNER JOIN opentalent.ContactPoint c ON oc.contactPoint_id = c.id
  20. WHERE oa.type='ADDRESS_HEAD_OFFICE' AND c.contactType='PRINCIPAL';