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

Postgres support (user defined types) #78

Open
54 of 83 tasks
Tracked by #40
nene opened this issue Apr 15, 2024 · 2 comments
Open
54 of 83 tasks
Tracked by #40

Postgres support (user defined types) #78

nene opened this issue Apr 15, 2024 · 2 comments

Comments

@nene
Copy link
Owner

nene commented Apr 15, 2024

Domains

  • CREATE DOMAIN
    • name [AS] data_type
    • COLLATE collation
    • DEFAULT expression
    • domain_constraint [ ... ]:
      • CONSTRAINT constraint_name
      • NOT NULL
      • NULL
      • CHECK (expression)
  • DROP DOMAIN
    • IF EXISTS
    • name, ...
    • CASCADE | RESTRICT
  • ALTER DOMAIN
    • SET DEFAULT expression | DROP DEFAULT
    • { SET | DROP } NOT NULL
    • ADD domain_constraint
      • CONSTRAINT name
      • CHECK (...)
      • NOT NULL
      • [ NOT VALID ]
    • DROP CONSTRAINT [ IF EXISTS ] constraint_name [ RESTRICT | CASCADE ]
    • RENAME CONSTRAINT constraint_name TO new_constraint_name
    • VALIDATE CONSTRAINT constraint_name
    • OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
    • RENAME TO new_name
    • SET SCHEMA new_schema

Types

  • CREATE TYPE
    • AS ( attribute_name data_type [ COLLATE collation ] [, ... ] )
    • AS ENUM ( 'label' [, ... ] )
    • AS RANGE ( ... ):
      • SUBTYPE = subtype
      • SUBTYPE_OPCLASS = subtype_operator_class
      • COLLATION = collation
      • CANONICAL = canonical_function
      • SUBTYPE_DIFF = subtype_diff_function
      • MULTIRANGE_TYPE_NAME = multirange_type_name
    • ( ... ):
      • INPUT = input_function
      • OUTPUT = output_function
      • RECEIVE = receive_function
      • SEND = send_function
      • TYPMOD_IN = type_modifier_input_function
      • TYPMOD_OUT = type_modifier_output_function
      • ANALYZE = analyze_function
      • SUBSCRIPT = subscript_function
      • INTERNALLENGTH = { internallength | VARIABLE }
      • PASSEDBYVALUE
      • ALIGNMENT = alignment
      • STORAGE = storage
      • LIKE = like_type
      • CATEGORY = category
      • PREFERRED = preferred
      • ELEMENT = element
      • DELIMITER = delimiter
      • COLLATABLE = collatable
    • CREATE TYPE name;
  • DROP TYPE
    • IF EXISTS
    • name, ...
    • CASCADE | RESTRICT
  • ALTER TYPE
    • OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
    • RENAME TO new_name
    • SET SCHEMA new_schema
    • RENAME ATTRIBUTE attribute_name TO new_attribute_name
      • CASCADE | RESTRICT
    • action, ...:
      • ADD ATTRIBUTE attribute_name data_type
        • COLLATE collation
        • CASCADE | RESTRICT
      • DROP ATTRIBUTE attribute_name
        • IF EXISTS
        • CASCADE | RESTRICT
      • ALTER ATTRIBUTE attribute_name
        • [ SET DATA ] TYPE data_type
        • COLLATE collation
        • CASCADE | RESTRICT
    • ADD VALUE new_enum_value
      • IF NOT EXISTS
      • { BEFORE | AFTER } neighbor_enum_value
    • RENAME VALUE existing_enum_value TO new_enum_value
    • SET ( property = value [, ... ] )
This was referenced Apr 15, 2024
@maheshsundaram
Copy link

Thanks for documenting this! I would be glad to help out if I can figure out how. If you have any time and is convenient for you, can you point me to where I can begin?

@nene
Copy link
Owner Author

nene commented Apr 16, 2024

I guess you can look at existing commits to see how. This one might be a good start: 00adcae

The trickiest bit is figuring out the structure of the resulting syntax tree. For CREATE TYPE I guess it should be something like:

export interface CreateTypeStmt extends BaseNode {
  type: "create_type_stmt";
  createKw: Keyword<"CREATE">;
  typeKw: Keyword<"TYPE">;
  name: EntityName;
  // ENUM definition is probably the simplest, though others should fit here as well
  definition?: AsClause<EnumTypeDefinition>;
}

export interface EnumTypeDefinition extends BaseNode {
  type: "enum_type_definition";
  enumKw: Keyword<"ENUM">;
  values: ParenExpr<ListExpr<StringLiteral>>;
}

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