Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problème de concaténation sur valeur vide #97

Open
jbrieuclp opened this issue Jan 7, 2020 · 5 comments
Open

Problème de concaténation sur valeur vide #97

jbrieuclp opened this issue Jan 7, 2020 · 5 comments

Comments

@jbrieuclp
Copy link
Contributor

Salut il faudrait modifier cette ligne qui concatène nom et prénom avec l'opérateur ||

(upper(a.nom_role::text) || ' '::text) || a.prenom_role::text AS nom_complet,

par celle-ci
concat_ws(' '::text, upper(NULLIF(a.nom_role::text, ''::text)), NULLIF(a.prenom_role::text, ''::text)) AS nom_complet,
L'opérateur de concaténation || renvoi une chaîne vide si l'un ou l'autre est vide (ce qui peut arriver sur un prénom).

@amandine-sahl
Copy link
Contributor

Ce n'est pas la peine d'utiliser NULLIF il est géré par la fonction CONCAT

@jbrieuclp
Copy link
Contributor Author

C'est plutôt s'il y a une chaîne vide, si c'est le cas concat_ws l'espace sera ajouté :

select concat_ws(' ', 'truc', '') => 'truc '
select concat_ws(' ', 'truc', NULLIF('', '')) => 'truc'

@amandine-sahl
Copy link
Contributor

ok, effectivement.
Par ailleurs, c'est préférable de remplacer les chaines vides par des NULL.

@jbrieuclp
Copy link
Contributor Author

T'as complètement raison sur ce point

@camillemonchicourt
Copy link
Member

OK, ajouter un script d'update nettoyant cela.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants