postgres_scanner icon indicating copy to clipboard operation
postgres_scanner copied to clipboard

Can't create table with GEOMETRY type using CTAS

Open Maxxen opened this issue 6 months ago • 0 comments

What happens?

Original issue reported on discord.

This doesn't work.

CREATE TABLE postgres_db.my_schema.my_table AS 
    SELECT ST_Point (.22, 1.22) AS geom
-- Failed to copy data: ERROR:  Unknown WKB type (0)! Full WKB type number was (0)

But this does

CREATE TABLE postgres_db.my_schema.my_table (geom GEOMETRY);
INSERT INTO postgres_db.my_schema.my_table VALUES (ST_Point (.22, 1.22))

My guess is that during inserts we map the Postgres geometry type to WKB_BLOB, which spatial then auto-casts to from GEOMETRY. But this doesn't work during CTAS because no implicit cast get inserted.

To Reproduce

CREATE TABLE postgres_db.my_schema.my_table AS SELECT ST_Point (.22, 1.22) AS geom

OS:

MacOS

PostgreSQL Version:

14

DuckDB Version:

1.2.0

DuckDB Client:

CLI

Full Name:

Max Gabrielsson

Affiliation:

DuckDB Labs

Have you tried this on the latest main branch?

  • [x] I agree

Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

  • [x] I agree

Maxxen avatar Mar 28 '25 12:03 Maxxen