Error "1241 - Operand should contain 1 column" in Trigger that checks duplicities

Asked

Viewed 391 times

0

I’m doing this Rigger to check if it already exists dados_id and referente_obs in the bank table

But returns this error:

1241 - Operand should contain 1 column(s);

BEGIN
    IF (NEW.id_dados and NEW.referente_obs) not in (
        select A.id_dados,A.referente_obs
        From banco as A  
        where (NEW.id_dados = A.id_dados and NEW.referente_obs = A.referente_obs)
    ) THEN
       CALL `Insert Not Allowed.`;

    END IF;
END

2 answers

0

You cannot make a nested SELECT with two columns. You must separate it into two SELECT: one for A.id_data and one for A.re. It’s like this:

IF (NEW.id_dados and NEW.referente_obs) not in (
            select A.id_dados, A.referente_obs
            From banco as A  
            where (NEW.id_dados = A.id_dados and NEW.referente_obs = A.referente_obs)
)

Try it like this:

IF (NEW.id_dados NOT IN 
(
  SELECT A.id_dados
  FROM banco AS A  
  WHERE NEW.id_dados = A.id_dados
)) AND ((NEW.referente_obs) NOT IN
(
  SELECT A.referente_obs
  FROM banco AS A  
  WHERE NEW.referente_obs = A.referente_obs
))
  • Good afternoon Cleber, since already thank you for your attention tried to realize your idea but returned me #1241 - Operand should contain 2 column(s) <pre><code>BEFORE INSERT ON banco FOR EACH ROW BEGIN&#xA; IF (NEW.id_dados, NEW.referente_obs) not in (&#xA;(&#xA; select A.id_dados&#xA; From banco as A &#xA; where NEW.id_dados = A.id_dados&#xA;),&#xA;(&#xA; select A.referente_obs&#xA; From banco as A &#xA; where NEW.referente_obs = A.referente_obs&#xA;)) THEN CALL Insert Not Allowed.; END IF; END</code></pre>

  • I think you will have to dismember in two conditionals. I will edit the answer, see again after I change, please?

  • Cleber, I put the full Trigger in a reply above

0

BEFORE INSERT ON banco FOR EACH ROW BEGIN IF (NEW.id_dados, NEW.referente_obs) not in ( ( select A.id_dados From banco as A where NEW.id_dados = A.id_dados ), ( select A.referente_obs From banco as A where NEW.referente_obs = A.referente_obs )) THEN CALL Insert Not Allowed.; END IF; END

Browser other questions tagged

You are not signed in. Login or sign up in order to post.