1

I need solution for my problem. Thanks in advance. I use Derby DB.

I have one table with few columns. I created trigger after update for specific columns that I need. When I try to update columns in row I get this error.

Error code 30000, SQL state 21000: Scalar subquery is only allowed to return a single row.

This error only appears when I have two or more rows in main table. If I have only one row in table "accounts" everything works fine.

This is code for trigger: (accounts is main table, accounts_history new table)

CREATE TRIGGER aft_update AFTER UPDATE of balance,date
           ON  accounts  

FOR EACH ROW MODE DB2SQL

insert into accounts_history   

(old_id,new_name,new_balance,new_date) values
            (

(select id from accounts),(select name from accounts),

(select balance from accounts),(select date from accounts) 
            );
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786

1 Answers1

1

A scalar subquery is supposed to return at most one row and exactly one column.

Just use insert . . . select:

insert into accounts_history(old_id, new_name, new_balance, new_date)
    select id, name, balance, date
    from accounts;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786