taozhi8833998/node-sql-parser

CREATE TYPE does not respect created type.

Closed this issue · 6 comments

Describe the bug
CREATE TYPE does not respect created type. Creation of type succeed but later when using the type as a column it will error.

Database Engine
PostgreSQL.

To Reproduce
-the SQL that be parsed
-the node-sql-parser version
-the node version

CREATE TYPE access_key_permission_kind AS ENUM ('FULL_ACCESS', 'FUNCTION_CALL');

CREATE TABLE
access_keys (
public_key text NOT NULL,
account_id text NOT NULL,
permission_kind access_key_permission_kind NOT NULL,
CONSTRAINT access_keys_pk PRIMARY KEY (public_key, account_id)
)

Expected behavior
access_key_permission_kind exist due to create type as enum.

Screenshots
If applicable, add screenshots to help explain your problem.
Screenshot 2024-02-12 at 2 46 12 PM
Screenshot 2024-02-12 at 2 47 01 PM

Additional context
"node-sql-parser": "4.18.0",

rawschema from log
'CREATE TYPE
access_key_permission_kind AS ENUM('FULL_ACCESS', 'FUNCTION_CALL');

CREATE TABLE
access_keys (
public_key text NOT NULL,
account_id text NOT NULL,
created_by_receipt_id text NULL,
deleted_by_receipt_id text NULL,
permission_kind access_key_permission_kind NOT NULL CONSTRAINT access_keys_pk PRIMARY KEY (public_key, account_id)
)'

TEST:

{
title: 'create type as enum and use type as tablename',
sql: [
CREATE TYPE access_key_permission_kind AS ENUM ( 'A', 'B' ); CREATE TABLE access_keys(id SERIAL PRIMARY KEY, name VARCHAR, permission_kind access_key_permission_kind); ,
CREATE TYPE "access_key_permission_kind" AS ENUM ('A', 'B'); CREATE TABLE access_keys(id SERIAL PRIMARY KEY, name VARCHAR, permission_kind access_key_permission_kind);
]
},

@Kevin101Zhang supported custom data type now. Sorry for the late reply.

Nice! I cloned and have been trying to make progress in your repo for the past 2 days. It was my first time learning a pegjs so it was very informative to dig through your code and learn how the AST is created. Thanks you for taking care of it. I also noticed it does not recognize partitions. If there is a roadmap with this feature It would be great if you could link it here. Also would be happy to learn how you're introducing these changes since they are very informative to look at.

partition testcase:

{
title: 'parition by hash',
sql: [
CREATE TYPE access_key_permission_kind AS ENUM ( 'A', 'B' ); CREATE TABLE access_keys(id SERIAL PRIMARY KEY, name VARCHAR, permission_kind access_key_permission_kind, public_key text NOT NULL); PARTITION BY HASH (public_key); ,
CREATE TYPE "access_key_permission_kind" AS ENUM ('A', 'B') ; CREATE TABLE "access_keys" (id SERIAL PRIMARY KEY, name VARCHAR, permission_kind access_key_permission_kind, public_key TEXT NOT NULL); PARTITION BY HASH (public_key);
]
},

That's great to hear that you've been working with the repo and finding it informative! I'm glad you're enjoying learning about PEG.js and exploring the AST creation process. Thank you for your feedback regarding the partitions issue. I'll definitely look into adding that feature and will keep you updated on any roadmap developments. I appreciate your interest in how changes are introduced, and I'll make sure to share more insights on that as well. Feel free to reach out if you have any more questions or suggestions!

@Kevin101Zhang supported the partition by clause in the create table SQL syntax, check the above pr again.

Hey! Take your time here, but I'm curious if there's a release scheduled in the near future. I observed that your release history is somewhat spontaneous, so I'm interested to know when the next release is anticipated.

@Kevin101Zhang You can see the 5.0.0 milestone.