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

Support CREATE TYPE for creating custom type #535

Open
MRGRAVITY817 opened this issue Jul 8, 2022 · 5 comments
Open

Support CREATE TYPE for creating custom type #535

MRGRAVITY817 opened this issue Jul 8, 2022 · 5 comments

Comments

@MRGRAVITY817
Copy link
Contributor

Hello, I think it would be nice to add CREATE TYPE statement for creating custom composite type.

Use cases

-- Defining composite type
CREATE TYPE inventory_item AS (
    name            text,
    supplier_id     integer,
    price           numeric
);

-- Using composite type `inventory_item`
CREATE TABLE on_hand (
    item      inventory_item,
    count     integer
);
INSERT INTO on_hand VALUES (ROW('fuzzy dice', 42, 1.99), 1000);

References

@rex-remind101
Copy link

Just ran into this too.

@AugustoFKL
Copy link
Contributor

AugustoFKL commented Oct 2, 2022

@MRGRAVITY817 @rex-remind101 do you have any specific type to be supported? PostgreSQL and SQL Server seem not to follow the standard, so implementing each one of them would be a task by itself, isolated from the other ones.

The standard seems to be the easiest to expand, so I'd start with it, but I want to make sure of what exactly you need.

@teenjuna
Copy link

teenjuna commented Oct 5, 2022

Hey @AugustoFKL, I've also just ran into this. Could you please elaborate your question about any specific type? Personally, I just want this crate to be able to parse Postgres' CREATE TYPE ... AS (...) and CREATE TYPE ... AS ENUM (...)

@AugustoFKL
Copy link
Contributor

@teenjuna I see.

The problem is, CREATE TYPE ... AS (...) follows the standard (1), but the latest not. I'm currently mostly working to try to expand our ANSII implementation, or some others as I need. Otherwise, I don't have plans to work on that.

I could work on the first one, but not the CREATE TYPE ... AS ENUM. Does that help you?

[1] : https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#datetime-type

@teenjuna
Copy link

teenjuna commented Oct 6, 2022

@AugustoFKL any improvement will be very helpful, thank you!

It'll be also very helpful if you will consider the possibility that AS ENUM might be implemented in the future if you implement the ANSII variant (e.g. your implementation doesn't prevent this)! I might focus on this (as well as the INSERT INTO ... RETURNING and similar popular Postgres constructs) somewhere in the end of the year.

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

4 participants