4444 * column_default: string|null,
4545 * is_autoinc: bool|string,
4646 * sequence_name: string|null,
47- * enum_values : string|null,
47+ * values : string|null,
4848 * size: int|string|null,
4949 * scale: int|string|null,
5050 * contype: string|null,
@@ -292,7 +292,7 @@ protected function findColumns(TableSchemaInterface $table): bool
292292 )::varchar[],
293293 ',')
294294 ELSE NULL
295- END AS enum_values ,
295+ END AS values ,
296296 COALESCE(
297297 information_schema._pg_char_max_length(
298298 COALESCE(td.oid, tb.oid, a.atttypid),
@@ -467,7 +467,7 @@ protected function loadResultColumn(array $metadata): ?ColumnInterface
467467 )::varchar[],
468468 ',')
469469 ELSE NULL
470- END AS enum_values
470+ END AS values
471471 FROM pg_type AS t
472472 LEFT JOIN pg_type AS t2 ON t.typcategory='A' AND t2.oid = t.typelem OR t.typbasetype > 0 AND t2.oid = t.typbasetype
473473 LEFT JOIN pg_namespace AS ns ON ns.oid = COALESCE(t2.typnamespace, t.typnamespace)
@@ -486,8 +486,8 @@ protected function loadResultColumn(array $metadata): ?ColumnInterface
486486 }
487487
488488 $ columnInfo ['type ' ] = ColumnType::STRUCTURED ;
489- } elseif (!empty ($ typeInfo ['enum_values ' ])) {
490- $ columnInfo ['enumValues ' ] = explode (', ' , str_replace (["'' " ], ["' " ], $ typeInfo ['enum_values ' ]));
489+ } elseif (!empty ($ typeInfo ['values ' ])) {
490+ $ columnInfo ['values ' ] = explode (', ' , str_replace (["'' " ], ["' " ], $ typeInfo ['values ' ]));
491491 }
492492 }
493493
@@ -525,9 +525,9 @@ private function loadColumn(array $info): ColumnInterface
525525 'collation ' => $ collation ,
526526 'comment ' => $ info ['column_comment ' ],
527527 'dbType ' => $ dbType ,
528- 'enumValues ' => $ info ['enum_values ' ] !== null
529- ? explode (', ' , str_replace (["'' " ], ["' " ], $ info ['enum_values ' ]))
530- : null ,
528+ 'values ' => $ info ['values ' ] !== null
529+ ? explode (', ' , str_replace (["'' " ], ["' " ], $ info ['values ' ]))
530+ : $ this -> tryGetEnumValuesFromCheck ( $ info [ ' check ' ]) ,
531531 'name ' => $ info ['column_name ' ],
532532 'notNull ' => !$ info ['is_nullable ' ],
533533 'primaryKey ' => $ info ['contype ' ] === 'p ' ,
@@ -679,4 +679,31 @@ private function loadTableConstraints(string $tableName, string $returnType): ar
679679
680680 return $ result [$ returnType ];
681681 }
682+
683+ /**
684+ * @psalm-return list<string>|null
685+ */
686+ private function tryGetEnumValuesFromCheck (?string $ check ): ?array
687+ {
688+ if ($ check === null ) {
689+ return null ;
690+ }
691+
692+ preg_match_all (
693+ "~ANY\s*\(\(ARRAY\[('(?:''|[^'])*'[^,\]]*)(?:,\s*(?1))*~ " ,
694+ $ check ,
695+ $ block ,
696+ );
697+
698+ if (empty ($ block [0 ][0 ])) {
699+ return null ;
700+ }
701+
702+ preg_match_all ("~'((?:''|[^'])*)'~ " , $ block [0 ][0 ], $ matches );
703+
704+ return array_map (
705+ static fn ($ v ) => str_replace ("'' " , "' " , $ v ),
706+ $ matches [1 ] ?? [],
707+ );
708+ }
682709}
0 commit comments