-
Notifications
You must be signed in to change notification settings - Fork 591
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
Discussion: support Composite Types #14319
Comments
More specifically, do you mean the support of the |
May I ask which feature they want cannot be fulfilled by our |
probably they just want to have an alias to reuse the type instead of typing a long |
No feature can't be fulfilled by our |
I think it's possible to provide both syntax (with same implementation). Actually, there is a missing piece of If anyone is interested, I am happy to work this out. |
|
To be clear, the ways to alter the composite type of a column: postgres=# create type my_struct as (a int, b boolean);
CREATE TYPE
postgres=# create table my_table (v my_struct);
CREATE TABLE
postgres=# insert into my_table values ((1, false));
INSERT 0 1
postgres=# select * from my_table;
v
-------
(1,f)
(1 row)
postgres=# alter type my_struct add attribute c decimal;
ALTER TYPE
postgres=# select * from my_table;
v
--------
(1,f,)
(1 row)
postgres=# insert into my_table values ((2, true, 8.8));
INSERT 0 1
postgres=# select * from my_table;
v
-----------
(1,f,)
(2,t,8.8)
(2 rows)
postgres=# alter type my_struct drop attribute c restrict;
ALTER TYPE
postgres=# select * from my_table;
v
-------
(1,f)
(2,t)
(2 rows)
postgres=# create type my_struct_with_c as (a int, b boolean, c decimal);
CREATE TYPE
postgres=# CREATE FUNCTION my_struct_to_my_struct_with_c(source my_struct)
RETURNS my_struct_with_c
AS $$
DECLARE
result my_struct_with_c;
BEGIN
result.a := source.a;
result.b := source.b;
result.c := 0; -- Set the default value for c
RETURN result;
END;
$$
LANGUAGE plpgsql;
CREATE CAST (my_struct AS my_struct_with_c)
WITH FUNCTION my_struct_to_my_struct_with_c(my_struct)
AS IMPLICIT;
CREATE FUNCTION
CREATE CAST
postgres=# alter table my_table alter column v type my_struct_with_c;
ALTER TABLE
postgres=# select * from my_table;
v
---------
(1,f,0)
(2,t,0)
(2 rows) The latter one is more like how we may support "nested" schema change with anonymous composite types. As the affected table is specified and there's no such thing of mutable type catalog, most of the current design for schema change can be reused. If we're to support |
Also, we might need add some syntax sugar to support it better
And we can support
|
This issue has been open for 60 days with no activity. Could you please update the status? Feel free to continue discussion or close as not planned. |
Postgresql Composite Types : https://www.postgresql.org/docs/current/rowtypes.html
Should we support
Composite Types
? I added this issue because some users ask for this feature, even though they can use struct type to workaround.The text was updated successfully, but these errors were encountered: