Skip to content

Syntax error occurs when you try to insert a result of SELECT using WITH into a table #1682

Closed

Description

@mikageymir

Syntax error occurs when you try to insert a result of SELECT using WITH into a table.

:) WITH number * 2 AS num2 SELECT number, num2 FROM system.numbers LIMIT 3;

WITH number * 2 AS num2
SELECT
    number,
    num2
FROM system.numbers
LIMIT 3

┌─number─┬─num2─┐
│      0 │    0 │
│      1 │    2 │
│      2 │    4 │
└────────┴──────┘

3 rows in set. Elapsed: 0.007 sec.

:) CREATE TABLE test_number (number UInt64, num2 UInt64) ENGINE = Log;

CREATE TABLE test_number
(
    number UInt64,
    num2 UInt64
)
ENGINE = Log

Ok.

0 rows in set. Elapsed: 0.015 sec.

:) INSERT INTO test_number WITH number * 2 AS num2 SELECT number, num2 FROM system.numbers LIMIT 3;

Syntax error: failed at position 25:

INSERT INTO test_number WITH number * 2 AS num2 SELECT number, num2 FROM system.numbers LIMIT 3;

Expected one of: VALUES, FORMAT, OpeningRoundBracket, Dot, token, SELECT

:) INSERT INTO test_number SELECT number, number * 2 AS num2 FROM system.numbers LIMIT 3;

INSERT INTO test_number SELECT
    number,
    number * 2 AS num2
FROM system.numbers
LIMIT 3

Ok.

0 rows in set. Elapsed: 0.012 sec.

Activity

  1. added
    bug
    on Dec 21, 2017
  2. KochetovNicolai commented on Dec 21, 2017

    @KochetovNicolai
    Member

    Also you can use subquery as a workaround:

    INSERT INTO test_number SELECT * FROM (WITH number * 2 AS num2 SELECT number, num2 FROM system.numbers LIMIT 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions