@@ -61,29 +61,40 @@ $$ LANGUAGE plpgsql;
6161-- ! @brief Validate cast types in configuration
6262-- ! @internal
6363-- !
64- -- ! Checks that all 'cast_as' types specified in the configuration are valid.
65- -- ! Valid cast types are: text, int, small_int, big_int, real, double, boolean, date, jsonb.
64+ -- ! Checks that all 'cast_as' and 'plaintext_type' types specified in the configuration are valid.
65+ -- ! Valid cast types are: text, int, small_int, big_int, real, double, boolean, date, jsonb, json, float, decimal, timestamp .
6666-- !
6767-- ! @param jsonb Configuration data to validate
6868-- ! @return boolean True if all cast types are valid or no cast types specified
6969-- ! @throws Exception if any invalid cast type found
7070-- !
7171-- ! @note Used in CHECK constraint on eql_v2_configuration table
72- -- ! @note Empty configurations (no cast_as fields) are valid
72+ -- ! @note Empty configurations (no cast_as/plaintext_type fields) are valid
7373-- ! @note Cast type names are EQL's internal representations, not PostgreSQL native types
74+ -- ! @note 'plaintext_type' is accepted as a canonical alias for 'cast_as'
7475CREATE FUNCTION eql_v2 .config_check_cast(val jsonb)
7576 RETURNS BOOLEAN
77+ IMMUTABLE STRICT PARALLEL SAFE
7678AS $$
79+ DECLARE
80+ _valid_types text [] := ' {text, int, small_int, big_int, real, double, boolean, date, jsonb, json, float, decimal, timestamp}' ;
7781 BEGIN
78- -- If there are cast_as fields, validate them
82+ -- Validate cast_as fields
7983 IF EXISTS (SELECT jsonb_array_elements_text(jsonb_path_query_array(val, ' $.tables.*.*.cast_as' ))) THEN
80- IF (SELECT bool_and(cast_as = ANY(' {text, int, small_int, big_int, real, double, boolean, date, jsonb} ' ))
84+ IF NOT (SELECT bool_and(cast_as = ANY(_valid_types))
8185 FROM (SELECT jsonb_array_elements_text(jsonb_path_query_array(val, ' $.tables.*.*.cast_as' )) AS cast_as) casts) THEN
82- RETURN true;
86+ RAISE ' Configuration has an invalid cast_as (%). Cast should be one of %' , val, _valid_types;
87+ END IF;
88+ END IF;
89+
90+ -- Validate plaintext_type fields (canonical alias for cast_as)
91+ IF EXISTS (SELECT jsonb_array_elements_text(jsonb_path_query_array(val, ' $.tables.*.*.plaintext_type' ))) THEN
92+ IF NOT (SELECT bool_and(pt = ANY(_valid_types))
93+ FROM (SELECT jsonb_array_elements_text(jsonb_path_query_array(val, ' $.tables.*.*.plaintext_type' )) AS pt) types) THEN
94+ RAISE ' Configuration has an invalid plaintext_type (%). Type should be one of %' , val, _valid_types;
8395 END IF;
84- RAISE ' Configuration has an invalid cast_as (%). Cast should be one of {text, int, small_int, big_int, real, double, boolean, date, jsonb}' , val;
8596 END IF;
86- -- If no cast_as fields exist (empty config), that's valid
97+
8798 RETURN true;
8899 END;
89100$$ LANGUAGE plpgsql;
0 commit comments