0

I am trying to create the next table structure:

create type my_type1 as (val_s text);
create type my_type2 as (val_s text, val_t my_type1[]);
create table my_table(val_t my_type2[]);

And I want to write an insert query like this: insert into my_table (val_t) values ('{ "text", ''{"text1","text2"}'' }');

Please, help. I am using PostgreSQL 12

insert into my_table (val_t) values ('{ "text", ''{"text1","text2"}'' }');

3
  • Are you getting any error when executing your DDL and INSERT query ? Commented Apr 28, 2023 at 13:16
  • Yes, I can not run insert query. It is my main question. I found this solution stackoverflow.com/a/66384769/19593931 . But I want to insert without ARRAY and ROW keywords Commented Apr 28, 2023 at 13:30
  • The insert statement is repeated. It irritates me this way. Commented May 1, 2023 at 15:07

1 Answer 1

0

If your intention is to just have the data inserted as it is you can use the TEXT datatype

Schema (PostgreSQL v12)

CREATE TABLE my_table (
    val_t         text
);

insert into my_table (val_t) values ('{ "text", ''{"text1","text2"}'' }');

Query #1

SELECT * FROM my_table;
val_t
{ "text", '{"text1","text2"}' }

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, but I need UDTs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.