By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
CREATE TABLE interesant (
interesant_nip varchar(10)
);
CREATE FUNCTION normalize_nip(_input text) RETURNS varchar(10) AS $$
BEGIN
-- replace '' to NULL
IF (_input = '') THEN
RETURN NULL;
END IF;
-- remove '-' from string
RETURN REPLACE(_input, '-', '');
END; $$ LANGUAGE plpgsql;
INSERT INTO interesant VALUES
(normalize_nip('555-555-5555'));
SELECT * FROM interesant
1 rows affected
interesant_nip |
---|
5555555555 |