PARTITION statement is not handled correctly
- Dominant language
- Shell
- Stars
- 54
- Forks
- 12
- PR merge metrics
- No merged PRs in 30d
Description
Hello.
We have a PostgreSQL database dump generated as follows:
```sql
--
-- 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:
```sql
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:
```sql
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](https://dev.mysql.com/doc/mysql-partitioning-excerpt/8.0/en/partitioning-list.html):
```sql
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)
);
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.