# LogicTest: local local-opt fakedist fakedist-opt fakedist-metadata

# Check that the various things in a table definition are properly escaped when
# printed out.
statement ok
CREATE table "woo; DROP USER humpty;" (x INT PRIMARY KEY); CREATE TABLE ";--notbetter" (
  x INT, y INT,
  "welp INT); -- concerning much
DROP USER dumpty;
CREATE TABLE unused (x " INT,
  INDEX "helpme ON (x)); -- this must stop!
DROP USER alice;
CREATE TABLE unused2(x INT, INDEX woo ON " (x ASC),
  FAMILY "nonotagain (x)); -- welp!
DROP USER queenofhearts;
CREATE TABLE unused3(x INT, y INT, FAMILY woo " (x, y),
  CONSTRAINT "getmeoutofhere PRIMARY KEY (x ASC)); -- saveme!
DROP USER madhatter;
CREATE TABLE unused4(x INT, CONSTRAINT woo " PRIMARY KEY (x)
) INTERLEAVE IN PARENT "woo; DROP USER humpty;" (x);

query TT
SHOW CREATE TABLE ";--notbetter"
----
";--notbetter"  CREATE TABLE ";--notbetter" (
                x INT8 NOT NULL,
                y INT8 NULL,
                "welp INT); -- concerning much
DROP USER dumpty;
CREATE TABLE unused (x " INT8 NULL,
  CONSTRAINT "getmeoutofhere PRIMARY KEY (x ASC)); -- saveme!
DROP USER madhatter;
CREATE TABLE unused4(x INT, CONSTRAINT woo " PRIMARY KEY (x ASC),
  INDEX "helpme ON (x)); -- this must stop!
DROP USER alice;
CREATE TABLE unused2(x INT, INDEX woo ON " (x ASC),
  FAMILY "nonotagain (x)); -- welp!
DROP USER queenofhearts;
CREATE TABLE unused3(x INT, y INT, FAMILY woo " (x, y, "welp INT); -- concerning much
DROP USER dumpty;
CREATE TABLE unused (x ")
) INTERLEAVE IN PARENT "woo; DROP USER humpty;" (x)

# Check that view creates handle strange things properly.
statement ok
CREATE VIEW ";--alsoconcerning" AS SELECT @1 AS a, @2 AS b, @3 AS c FROM ";--notbetter"

query TT
SHOW CREATE VIEW ";--alsoconcerning"
----
";--alsoconcerning"  CREATE VIEW ";--alsoconcerning" (a, b, c) AS SELECT @1 AS a, @2 AS b, @3 AS c FROM test.public.";--notbetter"

# Check that "create table as" handles strange things properly.
statement ok
CREATE TABLE ";--dontask" AS SELECT @1 AS a, @2 AS b, @3 AS c FROM ";--notbetter"

query TT
SHOW CREATE TABLE ";--dontask"
----
";--dontask"  CREATE TABLE ";--dontask" (
              a INT8 NULL,
              b INT8 NULL,
              c INT8 NULL,
              FAMILY "primary" (a, b, c, rowid)
)
