2016-11-02 17:34:29 +01:00
|
|
|
-- this version allows to search for a single term within many tables,
|
|
|
|
-- but behaves badly with multiple terms scattered in multiple tables.
|
|
|
|
|
2016-10-25 18:45:05 +02:00
|
|
|
SELECT dossiers.id AS dossier_id,
|
2016-10-29 00:53:04 +02:00
|
|
|
dossiers.id::text || ' ' ||
|
|
|
|
COALESCE(users.email, '') AS term
|
2016-10-25 18:45:05 +02:00
|
|
|
FROM dossiers
|
2016-10-29 00:53:04 +02:00
|
|
|
INNER JOIN users ON users.id = dossiers.user_id
|
2016-10-25 18:45:05 +02:00
|
|
|
|
|
|
|
UNION SELECT cerfas.dossier_id,
|
2016-10-29 00:53:04 +02:00
|
|
|
COALESCE(cerfas.content, '') AS term
|
2016-10-25 18:45:05 +02:00
|
|
|
FROM cerfas
|
|
|
|
|
|
|
|
UNION SELECT champs.dossier_id,
|
2016-10-29 00:53:04 +02:00
|
|
|
COALESCE(champs.value, '') || ' ' ||
|
|
|
|
COALESCE(drop_down_lists.value, '') AS term
|
2016-10-28 19:34:29 +02:00
|
|
|
FROM champs
|
|
|
|
INNER JOIN drop_down_lists ON drop_down_lists.type_de_champ_id = champs.type_de_champ_id
|
2016-10-25 18:45:05 +02:00
|
|
|
|
|
|
|
UNION SELECT entreprises.dossier_id,
|
2016-10-29 00:53:04 +02:00
|
|
|
COALESCE(entreprises.siren, '') || ' ' ||
|
|
|
|
COALESCE(entreprises.numero_tva_intracommunautaire, '') || ' ' ||
|
|
|
|
COALESCE(entreprises.forme_juridique, '') || ' ' ||
|
|
|
|
COALESCE(entreprises.forme_juridique_code, '') || ' ' ||
|
|
|
|
COALESCE(entreprises.nom_commercial, '') || ' ' ||
|
|
|
|
COALESCE(entreprises.raison_sociale, '') || ' ' ||
|
|
|
|
COALESCE(entreprises.siret_siege_social, '') || ' ' ||
|
|
|
|
COALESCE(entreprises.nom, '') || ' ' ||
|
|
|
|
COALESCE(entreprises.prenom, '') || ' ' ||
|
|
|
|
COALESCE(rna_informations.association_id, '') || ' ' ||
|
|
|
|
COALESCE(rna_informations.titre, '') || ' ' ||
|
|
|
|
COALESCE(rna_informations.objet, '') AS term
|
2016-10-25 18:45:05 +02:00
|
|
|
FROM entreprises
|
2016-10-29 00:53:04 +02:00
|
|
|
LEFT JOIN rna_informations ON rna_informations.entreprise_id = entreprises.id
|
2016-10-25 18:45:05 +02:00
|
|
|
|
|
|
|
UNION SELECT etablissements.dossier_id,
|
2016-10-29 00:53:04 +02:00
|
|
|
COALESCE(etablissements.siret, '') || ' ' ||
|
|
|
|
COALESCE(etablissements.naf, '') || ' ' ||
|
|
|
|
COALESCE(etablissements.libelle_naf, '') || ' ' ||
|
|
|
|
COALESCE(etablissements.adresse, '') || ' ' ||
|
|
|
|
COALESCE(etablissements.code_postal, '') || ' ' ||
|
|
|
|
COALESCE(etablissements.localite, '') || ' ' ||
|
|
|
|
COALESCE(etablissements.code_insee_localite, '') AS term
|
2016-10-25 18:45:05 +02:00
|
|
|
FROM etablissements
|
|
|
|
|
|
|
|
UNION SELECT individuals.dossier_id,
|
2016-10-29 00:53:04 +02:00
|
|
|
COALESCE(individuals.nom, '') || ' ' ||
|
|
|
|
COALESCE(individuals.prenom, '') AS term
|
2016-10-25 18:45:05 +02:00
|
|
|
FROM individuals
|
|
|
|
|
|
|
|
UNION SELECT pieces_justificatives.dossier_id,
|
2016-10-29 00:53:04 +02:00
|
|
|
COALESCE(pieces_justificatives.content, '') AS term
|
2016-10-25 18:45:05 +02:00
|
|
|
FROM pieces_justificatives
|
|
|
|
|
|
|
|
UNION SELECT dossiers.id,
|
2016-10-29 00:53:04 +02:00
|
|
|
COALESCE(france_connect_informations.given_name, '') || ' ' ||
|
|
|
|
COALESCE(france_connect_informations.family_name, '') AS term
|
2016-10-25 18:45:05 +02:00
|
|
|
FROM france_connect_informations
|
|
|
|
INNER JOIN dossiers ON dossiers.user_id = france_connect_informations.user_id
|