Herramientas de usuario

Herramientas del sitio


informatica:base_de_datos:postgresql:postgresql_json

PostgreSQL JSON

Probar si un JSON es valido

CREATE OR REPLACE FUNCTION f_is_json(_txt text)
  RETURNS bool
  LANGUAGE plpgsql IMMUTABLE STRICT AS
$func$
BEGIN
   RETURN _txt::json IS NOT NULL;
EXCEPTION
   WHEN SQLSTATE '22P02' THEN  -- invalid_text_representation
      RETURN false;
END
$func$;
 
COMMENT ON FUNCTION f_is_json(text) IS 'Test if input text is valid JSON.
Returns true, false, or NULL on NULL input.'
informatica/base_de_datos/postgresql/postgresql_json.txt · Última modificación: 2026/02/12 01:10 por admin