Wrong columns in insert when used as a CTE
When using an insert query as a CTE, the "columns" part of the insert is wrongly generated, because it uses the aliased name of the table.
Example:
>>> from sql import Table, With
>>> test_table = Table("test_table")
>>> update_table = Table("test_table")
>>> data = Table("some_data")
>>> with_query = With(query=test_table.insert(
... columns=[test_table.id],
... values=data.select(data.value),
... returning=[test_table.id]))
>>> tuple(update_table.update(
... columns=[update_table.other],
... values=[with_query.id],
... with_=with_query,
... from_=[with_query]))
('WITH "a" AS (INSERT INTO "test_table" AS "b" ("b"."id") SELECT "c"."value" FROM "some_data" AS "c" RETURNING "b"."id") UPDATE "test_table" AS "d" SET "other" = "a"."id"
FROM "a" AS "a"', ())
Here, the '("b"."id")' in the values raises an error, because the columns part of the insert does not expect an alias here (Postgres 12)