I've got some empty string values being putting into my DB. Code I've used:

CREATE FUNCTION get_as_byte_array(anyelement) RETURNS INTEGER[] AS $$
      SELECT
        CASE 
          WHEN length($1::VARCHAR) = 0 THEN NULL
          ELSE
            (SELECT array_agg(get_byte($1::bytea, a)) FROM generate_series(0, length($1::bytea) - 1) a)
        END;
    $$ LANGUAGE SQL;

    SELECT get_as_byte_array(name_first), * FROM ja_customers WHERE id = 8154501;

Question: How can I find the responsible statement that is causing this issue? Would be possible to create a trigger to do that? If so, how?

UPDATE 1: According to some users, I can create a CONSTRAINT. This is even better indeed...

Could be something like:

ALTER TABLE public.ja_customers
      ADD CONSTRAINT cc_check_empty_strings CHECK (("name_last" != '',"company" != '',"address" != '');

?

This is related to my previous question: Blank (but not null) columns - PostgreSQL 9.2

有帮助吗?

解决方案

A constraint has been made to solve this issue:

 ALTER TABLE public.ja_customers
      ADD CONSTRAINT cc_check_empty_strings CHECK (("name_last" != '' AND "company" != '' AND "address" != ''));
许可以下: CC-BY-SA归因
不隶属于 dba.stackexchange
scroll top