Localosation:
https://github.com/NDXDeveloper/formation-postgresql-18/blob/main/04-objets-de-la-base-de-donnees/04.2-types-texte.md
Section: Comportement de TEXT (Exemple fourni)
Erreur: Le retour de la fonction pg_column_size() doit etre castee
postgres=# SELECT
postgres-# id,
postgres-# titre,
postgres-# LENGTH(contenu) AS longueur_caracteres,
postgres-# pg_size_pretty(pg_column_size(contenu)) AS taille_stockage
postgres-# FROM articles;
ERROR: function pg_size_pretty(integer) is not unique
LINE 5: pg_size_pretty(pg_column_size(contenu)) AS taille_stocka...
^
HINT: Could not choose a best candidate function. You might need to add explicit type casts
Correctif: un simple cast en numeric suffit
postgres=# SELECT
id,
titre,
LENGTH(contenu) AS longueur_caracteres,
pg_size_pretty(pg_column_size(contenu)::numeric) AS taille_stockage
FROM articles;
id | titre | longueur_caracteres | taille_stockage
----+---------------------------+---------------------+-----------------
1 | Introduction à PostgreSQL | 81 | 85 bytes
2 | Guide Complet PostgreSQL | 270000 | 3125 bytes
3 | Introduction à PostgreSQL | 81 | 85 bytes
4 | Guide Complet PostgreSQL | 270000 | 3125 bytes
(4 rows)
Cordialement
Localosation:
https://github.com/NDXDeveloper/formation-postgresql-18/blob/main/04-objets-de-la-base-de-donnees/04.2-types-texte.md
Section: Comportement de TEXT (Exemple fourni)
Erreur: Le retour de la fonction pg_column_size() doit etre castee
Correctif: un simple cast en numeric suffit
Cordialement