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

Support for CREATE TABLE table AS select_statement? #690

Closed
AlexErrant opened this issue Sep 10, 2023 · 4 comments · Fixed by #771
Closed

Support for CREATE TABLE table AS select_statement? #690

AlexErrant opened this issue Sep 10, 2023 · 4 comments · Fixed by #771
Labels
api Related to library's API enhancement New feature or request good first issue Good for newcomers greenlit Ready for implementation mysql Related to MySQL postgres Related to PostgreSQL sqlite Related to sqlite

Comments

@AlexErrant
Copy link
Contributor

I think this is a feature request, but does Kysely support creating a new (potentially temporary) table from a select statement?

This feature seems to be supported by the major databases; MySQL, PostGres, Sqlite.

@koskimas koskimas added enhancement New feature or request good first issue Good for newcomers api Related to library's API greenlit Ready for implementation labels Sep 12, 2023
@koskimas
Copy link
Member

koskimas commented Sep 12, 2023

Sounds like a good addition 👍. Let's add it.

The API would be:

db.schema
  .createTable('new_table')
  .as(db.selectFrom('person').select(['id', 'first_name']))

The function signature:

as(expr: Expression<unknown>) {
  ...
}

Temporary tables are already supported. You'd just use:

db.schema
  .createTable('new_table')
  .temporary()
  .as(db.selectFrom('person').select(['id', 'first_name']))

@igalklebanov igalklebanov added mysql Related to MySQL sqlite Related to sqlite postgres Related to PostgreSQL labels Sep 12, 2023
@LeoOmori
Copy link

hi, can i try to work on this?

@igalklebanov
Copy link
Member

@LeoOmori Go ahead, good luck! If you have any question, feel free to post in the contribution channel on discord.

@viraxslot
Copy link
Contributor

Hi all, there's no activity since september so I'd like to work on this issue.
@LeoOmori please ping me if you started to implement something and I have to stop :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to library's API enhancement New feature or request good first issue Good for newcomers greenlit Ready for implementation mysql Related to MySQL postgres Related to PostgreSQL sqlite Related to sqlite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants