Skip to content

Support CREATE TABLE table_name(...schema_fields) #4396

Closed

Description

@mvanschellebeeck

Describe the solution you'd like
Support the CREATE TABLE expression, e.g.
CREATE TABLE t1(a INTEGER, b INTEGER, c INTEGER, d INTEGER, e INTEGER);

Executing this with datafusion-cli shows:

DataFusion CLI v14.0.0
❯ CREATE TABLE t1(a INTEGER, b INTEGER, c INTEGER, d INTEGER, e INTEGER);
NotImplemented("Only `CREATE TABLE table_name AS SELECT ...` statement is supported")

Additional context
The ability to create a table with one statement and then insert values into it throughout a sessions forms the basis of a lot of sqllogictests we want to incorporate into testing. See #4248

Activity

  1. mvanschellebeeck commented on Nov 27, 2022

    @mvanschellebeeck
    ContributorAuthor

    An example of a set of queries we'd like to execute are:

    statement ok
    CREATE TABLE t1(a INTEGER, b INTEGER, c INTEGER, d INTEGER, e INTEGER)
    
    statement ok
    INSERT INTO t1(e,c,b,d,a) VALUES(103,102,100,101,104)
    
    statement ok
    INSERT INTO t1(a,c,d,e,b) VALUES(107,106,108,109,105)
    
    ...
    
    statement ok
    INSERT INTO t1(e,c,a,d,b) VALUES(177,176,179,178,175)
    
    statement ok
    INSERT INTO t1(b,e,a,d,c) VALUES(181,180,182,183,184)
    
    statement ok
    INSERT INTO t1(c,a,b,e,d) VALUES(187,188,186,189,185)
    
    statement ok
    INSERT INTO
    
    statement ok
    INSERT INTO t1(e,c,b,a,d) VALUES(242,244,240,243,241)
    
    statement ok
    INSERT INTO t1(e,d,c,b,a) VALUES(246,248,247,249,245)
    
    query I nosort
    SELECT CASE WHEN c>(SELECT avg(c) FROM t1) THEN a*2 ELSE b*10 END
      FROM t1
     ORDER BY 1
    ----
    30 values hashing to 3c13dee48d9356ae19af2515e05e6b54

    see here for reference

    Currently this is not possible since the CREATE TABLE expression is not supported.

  2. xudong963 commented on Dec 2, 2022

    @xudong963
    Member

    I'll do it (maybe on the weekend)

  3. self-assigned this
    on Dec 2, 2022
  4. melgenek commented on Jan 22, 2023

    @melgenek
    Contributor

    @xudong963 Hi! I see that the ticket is assigned to you, but I gave it a shot. I hope it's alright 🙂 . Here is the pr #5026.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions