You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an sql trigger which inserts data into special table called __streets after each insert in streets table.
In that trigger I use new.id which should be autogenerated because id column is created using AUTOINCREMENT.
But value of new.id inside of a trigger is NULL instead of the actual generated id.
trigger code:
CREATETRIGGERstreets_insert
AFTER insert
ON STREETS FOR EACH ROW
BEGININSERT INTO __streets (
id, name, created_at, updated_at
) VALUES (
new.id, new.name, new.created_at, new.updated_at
);
END
streets table:
CREATETABLEstreets (
id UNSIGNED NOT NULL AUTOINCREMENT,
name STRING NOT NULL,
created_at STRING,
updated_at STRING,
PRIMARY KEY(id)
)
_streets table:
CREATETABLE__streets (
__id UNSIGNED NOT NULL AUTOINCREMENT,
id UNSIGNED NOT NULL,
name STRING NOT NULL,
created_at STRING,
updated_at STRING,
PRIMARY KEY(__id)
)
Using simple sql insert statement without the trigger is working fine and generates new record:
INSERT INTO streets VALUES (NULL, 'street name', NULL, NULL)
Result being stored in streets table: [1, 'street name', null, null]
Using the statement insert with the trigger where id is specified also works fine:
INSERT INTO streets VALUES (2, 'street name', NULL, NULL)
Result being stored in streets table: [2, 'street name', null, null]
Result being stored in __streets table: [1, 2, 'street name', null, null]
But with trigger the same query produces following error because of new.id is NULL Failed to execute SQL statement: NOT NULL constraint failed: __STREETS.ID
Steps to reproduce
create two simple tables, e.g. streets and __streets using sql statements above
create trigger for streets table where new.id is used, e.g. as in the trigger mentioned above
insert data inside streets table with id as NULL
INSERT INTO streets VALUES (NULL, 'street name', NULL, NULL)
Actual behavior
new.id has NULL value inside of after trigger
Expected behavior
new.id should have generated id as value
The text was updated successfully, but these errors were encountered:
Bug description
I have an sql trigger which inserts data into special table called
__streets
after each insert instreets
table.In that trigger I use
new.id
which should be autogenerated becauseid
column is created using AUTOINCREMENT.But value of
new.id
inside of a trigger is NULL instead of the actual generated id.trigger code:
streets table:
_streets table:
Tarantool 2.6.2-0-g34d504d7d
Target: Linux-x86_64-RelWithDebInfo
Build options: cmake . -DCMAKE_INSTALL_PREFIX=/usr/local -DENABLE_BACKTRACE=ON
Compiler: /usr/bin/cc /usr/bin/c++
C_FLAGS: -fexceptions -funwind-tables -fno-omit-frame-pointer -fno-stack-protector -fno-common -fopenmp -msse2 -std=c11 -Wall -Wextra -Wno-strict-aliasing -Wno-char-subscripts -Wno-format-truncation -Wno-gnu-alignof-expression -fno-gnu89-inline -Wno-cast-function-type
CXX_FLAGS: -fexceptions -funwind-tables -fno-omit-frame-pointer -fno-stack-protector -fno-common -fopenmp -msse2 -std=c++11 -Wall -Wextra -Wno-strict-aliasing -Wno-char-subscripts -Wno-format-truncation -Wno-invalid-offsetof -Wno-gnu-alignof-expression -Wno-cast-function-type
Important notes
Using simple sql insert statement without the trigger is working fine and generates new record:
Result being stored in
streets
table:[1, 'street name', null, null]
Using the statement insert with the trigger where id is specified also works fine:
Result being stored in
streets
table:[2, 'street name', null, null]
Result being stored in
__streets
table:[1, 2, 'street name', null, null]
But with trigger the same query produces following error because of new.id is NULL
Failed to execute SQL statement: NOT NULL constraint failed: __STREETS.ID
Steps to reproduce
streets
and__streets
using sql statements abovestreets
table where new.id is used, e.g. as in the trigger mentioned abovestreets
table with id as NULLActual behavior
new.id
has NULL value inside of after triggerExpected behavior
new.id
should have generated id as valueThe text was updated successfully, but these errors were encountered: