@@ -2331,13 +2331,41 @@ defmodule Ecto.Adapters.PostgresTest do
2331
2331
primary_key: true ,
2332
2332
generated: "ALWAYS AS IDENTITY (MINVALUE 0 START WITH 0 INCREMENT BY 1)"
2333
2333
] } ,
2334
- { :add , :id_str , :string , [ generated: ~s| ALWAYS AS (id) STORED| ] } ,
2335
- { :add , :tags , { :array , :text } , [ generated: ~s| ALWAYS AS (ARRAY['foo','bar']) STORED| ] }
2334
+ { :add , :id_str , :string , [ generated: ~s| ALWAYS AS (id) STORED| ] }
2336
2335
] }
2337
2336
2338
2337
assert execute_ddl ( create ) == [
2339
2338
"""
2340
- 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"))
2339
+ 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"))
2340
+ """
2341
+ |> remove_newlines
2342
+ ]
2343
+ end
2344
+
2345
+ test "create table with generated array column" do
2346
+ create =
2347
+ { :create , table ( :posts ) ,
2348
+ [ { :add , :tags , { :array , :text } , [ generated: ~s| ALWAYS AS (ARRAY['foo','bar']) STORED| ] } ] }
2349
+
2350
+ assert execute_ddl ( create ) == [
2351
+ """
2352
+ CREATE TABLE "posts" ("tags" text[] GENERATED ALWAYS AS (ARRAY['foo','bar']) STORED)
2353
+ """
2354
+ |> remove_newlines
2355
+ ]
2356
+ end
2357
+
2358
+ test "create table with generated nested array column" do
2359
+ create =
2360
+ { :create , table ( :posts ) ,
2361
+ [
2362
+ { :add , :tags , { :array , { :array , :text } } ,
2363
+ [ generated: ~s| ALWAYS AS (ARRAY['foo','bar']) STORED| ] }
2364
+ ] }
2365
+
2366
+ assert execute_ddl ( create ) == [
2367
+ """
2368
+ CREATE TABLE "posts" ("tags" text[][] GENERATED ALWAYS AS (ARRAY['foo','bar']) STORED)
2341
2369
"""
2342
2370
|> remove_newlines
2343
2371
]
0 commit comments