Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PARTITION statement is not handled correctly #57

Open
bolduz opened this issue Sep 19, 2024 · 1 comment
Open

PARTITION statement is not handled correctly #57

bolduz opened this issue Sep 19, 2024 · 1 comment

Comments

@bolduz
Copy link

bolduz commented Sep 19, 2024

Hello.
We have a PostgreSQL database dump generated as follows:

--
-- PostgreSQL database dump
--

-- Dumped from database version 15.6
-- Dumped by pg_dump version 15.6

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

with a list of CREATE TABLE statements, some of which are for partitioned tables:

CREATE TABLE public.samples (
    id bigint NOT NULL,
    machine_id bigint,
    device_id character varying NOT NULL,
    sampled_at timestamp(6) without time zone NOT NULL,
    data jsonb,
    created_at timestamp(6) without time zone NOT NULL,
    updated_at timestamp(6) without time zone NOT NULL
)
PARTITION BY LIST (device_id);

This results in the following SQL code, which creates a syntax error due to the additional backticks in the last two lines:

CREATE TABLE public.samples (
    `id` bigint NOT NULL,
    `machine_id` bigint,
    `device_id` longtext NOT NULL,
    `sampled_at` timestamp(6) NOT NULL,
    `data` json,
    `created_at` timestamp(6) NOT NULL,
    `updated_at` timestamp(6) NOT NULL
``)
`PARTITION` BY LIST (device_id);

Even fixing the syntax error could not work, since MySQL wants LIST partitions defined at that point (otherwise you will get the error For LIST partitions each partition must be defined when loading the SQL file).

From MySQL docs at https://dev.mysql.com/doc/mysql-partitioning-excerpt/8.0/en/partitioning-list.html:

CREATE TABLE employees (
    id INT NOT NULL,
    fname VARCHAR(30),
    lname VARCHAR(30),
    hired DATE NOT NULL DEFAULT '1970-01-01',
    separated DATE NOT NULL DEFAULT '9999-12-31',
    job_code INT,
    store_id INT
)
PARTITION BY LIST(store_id) (
    PARTITION pNorth VALUES IN (3,5,6,9,17),
    PARTITION pEast VALUES IN (1,2,10,11,19,20),
    PARTITION pWest VALUES IN (4,12,13,14,18),
    PARTITION pCentral VALUES IN (7,8,15,16)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@bolduz and others