Supposing, I have a table:
create table mytable (
"x" text,
"y" text
);
And I have arrays with values for x and for y called arr_x and arr_y:
["x1", "x2", "x3"]
["y1", "y2", "y3"]
I want to insert these values with one query. The desired result is:
x | y
-------
x1 | y1
x2 | y2
x3 | y3
I tried to do something like that, but it failed:
insert into mytable ("x", "y")
select unnest(arr_x::text), unnest(arr_y::text);
Any idea how can I insert the values? I am new in Postgres.
::text[]?