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

[BUG]: INSERT INTO … SELECT does not work with generated columns #3971

Open
1 task done
hyunbinseo opened this issue Jan 19, 2025 · 1 comment
Open
1 task done
Labels
bug Something isn't working

Comments

@hyunbinseo
Copy link

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.38.4

What version of drizzle-kit are you using?

0.30.2

Other packages

No response

Describe the Bug

Reproduction. Use the mre-0 branch.

# Node.js 23
node src/index.ts

# Node.js 22
node --experimental-strip-types src/index.ts
import { db } from './db/index.ts';
import { userTable } from './db/schema.ts';

await db // works
  .insert(userTable)
  .values({ deactivatedAt: new Date() })
  .returning();

await db // fails
  .insert(userTable)
  .select(db.select({ deactivatedAt: userTable.deactivatedAt }).from(userTable));

Error: Insert select error: selected fields are not the same or are in a different order compared to the table definition (at SQLiteInsertBuilder.select)

// schema.ts
import { sql, type SQL } from 'drizzle-orm';
import { integer, sqliteTable } from 'drizzle-orm/sqlite-core';

export const userTable = sqliteTable('user', {
  id: integer().primaryKey(),
  deactivatedAt: integer({ mode: 'timestamp' }),
  isDeactivated: integer({ mode: 'boolean' }) //
    .generatedAlwaysAs((): SQL => sql`${userTable.deactivatedAt} IS NOT NULL`),
});
@Vinlock
Copy link

Vinlock commented Jan 20, 2025

This is killing me rn with MySQL :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants