apecloud / myduckserver

MySQL & Postgres Analytics, Reimagined
187 stars 9 forks source link

Duplicated column entries appear when connecting to MyDuck Server via psql. #172

Closed TianyuZhang1214 closed 5 days ago

TianyuZhang1214 commented 6 days ago

1. Execute the following SQL on PostgreSQL to create a schema and populate a table:

-- Create a schema
CREATE SCHEMA test_schema;

-- Create a table within the schema
CREATE TABLE test_schema.test_table (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100),
    age INT
);

-- Insert multiple rows into the table
INSERT INTO test_schema.test_table (name, age) 
VALUES 
    ('Alice', 30),
    ('Bob', 25),
    ('Charlie', 35);

2. Execute the following SQL on DuckDB using psql to attach the PostgreSQL database and copy data:

-- Attach the PostgreSQL database to DuckDB
ATTACH 'dbname=postgres user=postgres password=root host=127.0.0.1 port=15432' AS pg_postgres (TYPE POSTGRES);

-- Copy data from PostgreSQL database into DuckDB
COPY FROM DATABASE pg_postgres TO mysql;

3. Query the information_schema.columns in DuckDB to inspect the table structure:

SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'test_table';

The output is:

 column_name | data_type | is_nullable
-------------+-----------+-------------
 id          | INTEGER   | NO
 name        | VARCHAR   | YES
 age         | INTEGER   | YES
 id          | INTEGER   | NO
 name        | VARCHAR   | YES
 age         | INTEGER   | YES
(6 rows)

You can find the duplicated columns.

fanyang01 commented 5 days ago
psql -h 127.0.0.1 -U mysql

mysql=> create table t (id int, name text, age int);
CREATE TABLE
mysql=> SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 't';
 column_name | data_type | is_nullable
-------------+-----------+-------------
 id          | INTEGER   | YES
 name        | VARCHAR   | YES
 age         | INTEGER   | YES

mysql=>

Were you running this query on a dirty database? I cannot reproduce it.

TianyuZhang1214 commented 5 days ago
psql -h 127.0.0.1 -U mysql

mysql=> create table t (id int, name text, age int);
CREATE TABLE
mysql=> SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 't';
 column_name | data_type | is_nullable
-------------+-----------+-------------
 id          | INTEGER   | YES
 name        | VARCHAR   | YES
 age         | INTEGER   | YES

mysql=>

Were you running this query on a dirty database? I cannot reproduce it.

The description has been updated.