Skip to content
New issue

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

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

Already on GitHub? # to your account

insertBatch() generates SQL that throws an error #284

Closed
Tigrov opened this issue Oct 18, 2024 · 0 comments
Closed

insertBatch() generates SQL that throws an error #284

Tigrov opened this issue Oct 18, 2024 · 0 comments
Labels

Comments

@Tigrov
Copy link
Member

Tigrov commented Oct 18, 2024

$db
    ->createCommand()
    ->createTable(
        '{{%user}}',
        [
            'id' => 'pk',
            'number' => 'integer NOT NULL',
            'email' => 'string(255) NOT NULL',
            'balance' => 'float DEFAULT 0.0 NOT NULL',
            'born_at' => 'date',
        ],
    )
    ->execute();

$db
    ->createCommand()
    ->batchInsert(
        '{{%user}}',
        ['number', 'email', 'balance', 'born_at'],
        $fixtures,
    )
    ->execute();

The above code generates SQL

INSERT ALL 
INTO "user" ("number", "email", "balance", "born_at") VALUES (1, 'foo@bar\baz', '10.25', NULL)
INTO "user" ("number", "email", "balance", "born_at") VALUES (2, 'bar@foo', '1', NULL) 
INTO "user" ("number", "email", "balance", "born_at") VALUES (3, 'seed@beat', '100', NULL) 
INTO "user" ("number", "email", "balance", "born_at") VALUES (4, 'the@best', '500', NULL) 
INTO "user" ("number", "email", "balance", "born_at") VALUES (5, 'test@test', '42', TO_DATE('1990-01-01', 'yyyy-mm-dd'))
SELECT 1
FROM SYS.DUAL

Which throws an error

SQLSTATE[HY000]: General error: 1 OCIStmtExecute: ORA-00001: unique constraint (SYSTEM.SYS_C007804) violated on
table XE.user columns (id)
ORA-03301: (ORA-00001 details) row with column values (id:1) already exists
Help: https://docs.oracle.com/error-help/db/ora-00001/

Additioanal info

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant