Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autogenerated id inside new object is null in sql after trigger #6020

Open
AlexanderBich opened this issue Apr 19, 2021 · 0 comments
Open

autogenerated id inside new object is null in sql after trigger #6020

AlexanderBich opened this issue Apr 19, 2021 · 0 comments
Labels
bug Something isn't working sql

Comments

@AlexanderBich
Copy link

Bug description

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:

CREATE TRIGGER streets_insert
    AFTER insert
    ON STREETS FOR EACH ROW
BEGIN
    INSERT INTO __streets (
        id, name, created_at, updated_at
    ) VALUES (
        new.id, new.name, new.created_at, new.updated_at
    );
END

streets table:

CREATE TABLE streets (
    id UNSIGNED NOT NULL AUTOINCREMENT,
    name STRING NOT NULL,
    created_at STRING,
    updated_at STRING,
    PRIMARY KEY(id)
)

_streets table:

CREATE TABLE __streets (
    __id UNSIGNED NOT NULL AUTOINCREMENT,
    id UNSIGNED NOT NULL,
    name STRING NOT NULL,
    created_at STRING,
    updated_at STRING, 
    PRIMARY KEY(__id)
)
  • OS: [e.g. Linux]
  • OS Version: [e.g. Ubuntu 20.04.1]
  • Architecture: [amd64]

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:

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

  1. create two simple tables, e.g. streets and __streets using sql statements above
  2. create trigger for streets table where new.id is used, e.g. as in the trigger mentioned above
  3. 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

@AlexanderBich AlexanderBich added the bug Something isn't working label Apr 19, 2021
@kyukhin kyukhin added this to the wishlist milestone Jul 14, 2021
@kyukhin kyukhin removed this from the wishlist milestone Jun 27, 2022
@igormunkin igormunkin removed the teamL label Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sql
Projects
None yet
Development

No branches or pull requests

3 participants