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 Using Another Table #216

Open
rmorais01 opened this issue Dec 15, 2023 · 3 comments
Open

Support for Create Table Using Another Table #216

rmorais01 opened this issue Dec 15, 2023 · 3 comments
Labels
wontfix This will not be worked on

Comments

@rmorais01
Copy link

Is your feature request related to a problem? Please describe.
A very useful addition to the simple-ddl-parser would be the ability to parse and process the SQL Create Table Using Another Table. Currently there is support only for the Create command, and hence this feature will extend the functionality of this DDL parser.

Describe the solution you'd like
The solution must be able to parse the SQL CREATE command and create the table structure by referencing the table in the select statement which must exist in the same file. The new table gets the same column definitions.

Describe alternatives you've considered
NA

Additional context
Here are some examples for the Create Table Using Another Table command
Syntax
CREATE TABLE new_table_name AS
SELECT column1, column2,...
FROM existing_table_name
WHERE ....;

Example
CREATE TABLE Person (
person_id int,
last_name varchar(255),
first_name varchar(255),
address varchar(255),
city varchar(255)
);

CREATE TABLE TestTable AS
SELECT person_id, first_name, last_name
FROM Person;

@dmaresma
Copy link
Contributor

dmaresma commented Jan 3, 2024

It's quite difficult it's require a db connection to derive SQL Select statement INTO a valid table definition and project the metadata with sp_help_text or get_ddl functions. the module doesn't include a database engine for derivation you are looking for.

@xnuinside
Copy link
Owner

@dmaresma I think idea was if create table exists in same ddl script. In that case it is possible.

@xnuinside
Copy link
Owner

https://dev.mysql.com/doc/refman/8.0/en/create-table-like.html - we have support for 'LIKE' and 'CLONE' statements. I don't like idea to add SELECT - because it is part of DML, not DDL, but I will think about it, maybe add support only for this case

@xnuinside xnuinside added the wontfix This will not be worked on label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants