add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
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 text
);

CREATE FUNCTION normalize_nip() RETURNS TRIGGER AS $$
BEGIN
-- replace '' to NULL
IF (NEW.interesant_nip LIKE '') THEN
NEW.interesant_nip := NULL;
RETURN NEW;
END IF;

-- remove '-' from string
NEW.interesant_nip := REPLACE(NEW.interesant_nip, '-', '');

RETURN NEW;
END; $$ LANGUAGE plpgsql;

CREATE TRIGGER interesant_nip_normalize BEFORE INSERT OR UPDATE ON interesant FOR EACH ROW EXECUTE PROCEDURE normalize_nip()
INSERT INTO interesant VALUES ('555-555-5555');

SELECT * FROM interesant
1 rows affected
interesant_nip
5555555555