diff --git a/lib/ecto/adapters/postgres/connection.ex b/lib/ecto/adapters/postgres/connection.ex index bb045a54..f023bfb3 100644 --- a/lib/ecto/adapters/postgres/connection.ex +++ b/lib/ecto/adapters/postgres/connection.ex @@ -1750,8 +1750,10 @@ if Code.ensure_loaded?(Postgrex) do defp options_expr(options), do: [?\s, options] - defp column_type({:array, type}, opts), - do: [column_type(type, opts), "[]"] + defp column_type({:array, type}, opts) do + [type, opts] = column_type(type, opts) + [type, "[]", opts] + end defp column_type(type, opts) when type in ~w(time utc_datetime naive_datetime)a do generated = Keyword.get(opts, :generated) diff --git a/test/ecto/adapters/postgres_test.exs b/test/ecto/adapters/postgres_test.exs index 02633427..b88d35fc 100644 --- a/test/ecto/adapters/postgres_test.exs +++ b/test/ecto/adapters/postgres_test.exs @@ -2331,12 +2331,13 @@ defmodule Ecto.Adapters.PostgresTest do primary_key: true, generated: "ALWAYS AS IDENTITY (MINVALUE 0 START WITH 0 INCREMENT BY 1)" ]}, - {:add, :id_str, :string, [generated: ~s|ALWAYS AS (id) STORED|]} + {:add, :id_str, :string, [generated: ~s|ALWAYS AS (id) STORED|]}, + {:add, :tags, {:array, :text}, [generated: ~s|ALWAYS AS (ARRAY['foo','bar']) STORED|]} ]} assert execute_ddl(create) == [ """ - CREATE TABLE "posts" ("id" integer GENERATED ALWAYS AS IDENTITY (MINVALUE 0 START WITH 0 INCREMENT BY 1), "id_str" varchar(255) GENERATED ALWAYS AS (id) STORED, PRIMARY KEY ("id")) + CREATE TABLE "posts" ("id" integer GENERATED ALWAYS AS IDENTITY (MINVALUE 0 START WITH 0 INCREMENT BY 1), "id_str" varchar(255) GENERATED ALWAYS AS (id) STORED, \"tags\" text[] GENERATED ALWAYS AS (ARRAY['foo','bar']) STORED, PRIMARY KEY ("id")) """ |> remove_newlines ]