File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 337337DO $$
338338DECLARE
339339 v_conname name;
340+ v_conkey int2[];
340341BEGIN
341342 SELECT conname into v_conname FROM pg_constraint WHERE
342343 contype = 'c'
@@ -353,8 +354,18 @@ BEGIN
353354 END IF;
354355
355356 ALTER TABLE ${ ident ( old ! . schema ) } .${ ident ( old ! . table ) } ADD CONSTRAINT ${ ident (
356- old ! . table
357- ) } _${ ident ( old ! . name ) } _check CHECK (${ check } );
357+ `${ old ! . table } _${ old ! . name } _check`
358+ ) } CHECK (${ check } );
359+
360+ SELECT conkey into v_conkey FROM pg_constraint WHERE conname = ${ literal (
361+ `${ old ! . table } _${ old ! . name } _check`
362+ ) } ;
363+
364+ ASSERT v_conkey IS NOT NULL, 'error creating column constraint: check condition must refer to this column';
365+ ASSERT cardinality(v_conkey) = 1, 'error creating column constraint: check condition cannot refer to multiple columns';
366+ ASSERT v_conkey[1] = ${ literal (
367+ old ! . ordinal_position
368+ ) } , 'error creating column constraint: check condition cannot refer to other columns';
358369END
359370$$;
360371`
You can’t perform that action at this time.
0 commit comments