File tree 2 files changed +36
-2
lines changed
2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 83
83
WHERE contype = ' u' AND cardinality(conkey) = 1
84
84
) AS uniques ON uniques .table_id = c .oid AND uniques .ordinal_position = a .attnum
85
85
LEFT JOIN (
86
- SELECT
86
+ -- We only select the first column check
87
+ SELECT DISTINCT ON (table_id, ordinal_position)
87
88
conrelid AS table_id,
88
89
conkey[1 ] AS ordinal_position,
89
90
substring (
93
94
) AS " definition"
94
95
FROM pg_constraint
95
96
WHERE contype = ' c' AND cardinality(conkey) = 1
96
- ORDER BY oid asc
97
+ ORDER BY table_id, ordinal_position, oid asc
97
98
) AS check_constraints ON check_constraints .table_id = c .oid AND check_constraints .ordinal_position = a .attnum
98
99
WHERE
99
100
NOT pg_is_other_temp_schema(nc .oid )
Original file line number Diff line number Diff line change @@ -899,3 +899,36 @@ create table public.t (
899
899
900
900
await pgMeta . query ( `drop table public.t;` )
901
901
} )
902
+
903
+ test ( 'column with multiple checks' , async ( ) => {
904
+ await pgMeta . query ( `create table t(c int8 check (c != 0) check (c != -1))` )
905
+
906
+ const res = await pgMeta . columns . list ( )
907
+ const columns = res . data
908
+ ?. filter ( ( c ) => c . schema === 'public' && c . table === 't' )
909
+ . map ( ( { id, table_id, ...c } ) => c )
910
+ expect ( columns ) . toMatchInlineSnapshot ( `
911
+ [
912
+ {
913
+ "check": "c <> 0",
914
+ "comment": null,
915
+ "data_type": "bigint",
916
+ "default_value": null,
917
+ "enums": [],
918
+ "format": "int8",
919
+ "identity_generation": null,
920
+ "is_generated": false,
921
+ "is_identity": false,
922
+ "is_nullable": true,
923
+ "is_unique": false,
924
+ "is_updatable": true,
925
+ "name": "c",
926
+ "ordinal_position": 1,
927
+ "schema": "public",
928
+ "table": "t",
929
+ },
930
+ ]
931
+ ` )
932
+
933
+ await pgMeta . query ( `drop table t` )
934
+ } )
You can’t perform that action at this time.
0 commit comments