Skip to content

New rule: check constraints can not have subqueries #1226

Description

@obbteam

Context:
Just found out that subqueries can not be used in the check constraint.
Squawk linter does not complain but Postgresql throws the following error:
ERROR: cannot use subquery in check constraint (SQLSTATE 0A000)

Example:

ALTER TABLE
	table_x
ADD
	CONSTRAINT bar_should_equal_to_banana CHECK (
		(
			SELECT
				bar
			FROM
				table_y
			WHERE
				table_y.pk = table_x.y_pk
		) = 'banana'
	);

Expected fix:
New rule should throw an error on subqueries used in the check constraint.
Should suggest to use triggers instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions