最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

database - Create DuckDB table with primary key from parquet - Stack Overflow

programmeradmin2浏览0评论

I am trying to set up a simple but large DuckDB database with a single column of unique values as read from a parquet file. For faster inference of single-point existence checking (WHERE id = test_id), I want to convert the parquet file to a DuckDB (as recommended) and add a primary key to it.

I tried it as follows:

CREATE OR REPLACE TABLE data (
    id UUID PRIMARY KEY
)
AS SELECT DISTINCT id FROM 'my-parquet-file.parquet'

but got the error:

duckdb.duckdb.ParserException: Parser Error: syntax error at or near "AS"

So what is the correct way of setting up the table for efficient single-point existence checking on huge tables?

I am trying to set up a simple but large DuckDB database with a single column of unique values as read from a parquet file. For faster inference of single-point existence checking (WHERE id = test_id), I want to convert the parquet file to a DuckDB (as recommended) and add a primary key to it.

I tried it as follows:

CREATE OR REPLACE TABLE data (
    id UUID PRIMARY KEY
)
AS SELECT DISTINCT id FROM 'my-parquet-file.parquet'

but got the error:

duckdb.duckdb.ParserException: Parser Error: syntax error at or near "AS"

So what is the correct way of setting up the table for efficient single-point existence checking on huge tables?

Share Improve this question edited Jan 19 at 10:09 NateDhaliwal 11210 bronze badges asked Jan 19 at 9:27 Bram VanroyBram Vanroy 28.4k26 gold badges147 silver badges263 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can add primary key via alter table ... add primary key ... after creation:

create or replace table data
as
select distinct id
from 'my-parquet-file.parquet';

alter table data add primary key (id);

or create table with primary key and then insert data into it:

create or replace table data (
    id uuid primary key
);

insert into data (id)
select distinct id
from 'my-parquet-file.parquet';
发布评论

评论列表(0)

  1. 暂无评论