Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vdQqo-000RpH-1F for pgsql-general@arkaria.postgresql.org; Wed, 07 Jan 2026 10:33:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdQqm-00DX4h-2x for pgsql-general@arkaria.postgresql.org; Wed, 07 Jan 2026 10:33:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vdQqm-00DX4Z-1Z for pgsql-general@lists.postgresql.org; Wed, 07 Jan 2026 10:33:13 +0000 Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vdQqk-0053yL-0z for pgsql-general@postgresql.org; Wed, 07 Jan 2026 10:33:12 +0000 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-3ec3cdcda4eso1368754fac.1 for ; Wed, 07 Jan 2026 02:33:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ridewithvia.com; s=google; t=1767781987; x=1768386787; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=i5Cbtsqr1ifGhQ9QD0xOYBvHahWuY2NU8dCkf/WQ5AI=; b=bA4Y90s0zFQGF3r6MhaukJAYh8d8YqPeH0tx9TbhDMPCUJc1NwQHSp7KxuhkTZ6f1D yCkqjC/5y2GT/jf+NQQzqAjtUGSXvejOV9HktT88VvZU+ClNyajj0pI2nKiRbCz4c3Fl dnoU0zlilw8OFQ2OsYo4lbsR5UnIQwHb+cECM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767781987; x=1768386787; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=i5Cbtsqr1ifGhQ9QD0xOYBvHahWuY2NU8dCkf/WQ5AI=; b=qFMHyiw+QWOr6SIGYxnx5RLbe1P/4h+pMBDSlFk2t0aRbEe/xD25U4Bc6e1fKdn+QD YfuVREmZQLVrjG9JkAY156Eyz2AMeXc8MthV6Ti39FRnqgNOJ2c2XMI1pFAqe2b4GMLY 0za5yHwwsxyyNHqrpI+gadm1LCvGNgWjBga1D/U1TR/QzLzE5IPp/C1ZnrYI3Y7PxrvB BmYXwkIxTmEwFj9HHm8o5StcFHSzrMQvrccn2iDfu2pxKj9uLiepxAmfkJ7X715LYag4 ip15p/gwWZQXoWta8QTMYDjLIzjPzfiDpNhWIY0hZagZHT74j96SwIgp+NO5+6gmx5Bx yf8A== X-Gm-Message-State: AOJu0YxR4UBN6ay1zgrwnq+VKyHU8xVb9ztZRbVi7k9sYL5WBsDLX9dQ 3rXH1BNJ7qCpzDwExOC3sVENyfUIooVcxwbhCu4VZNVCA9oyQM03f4x6six6v7rNNW1DNH7KKsh PxLRlKrI7ziLQCFASfghLiQCKsdYhcGjR/5rvvyKkXDQBfsR56eWsOtbdJp5V73K47W2ELe+6VH LsVd5Q4ksPZOcaepgXTIFw7/OV+PDqVmaVhsMCJACNl2gI6hAykg== X-Gm-Gg: AY/fxX5IEO65mllEU+SWsXLbHjQPDJui45f9aQcGavqjxKP0lNXw1ailr5eBJlqouy1 pEszP8Z5cyNu4nTY3wBy4mxGXpZ/WhgHga91r2KHaJN60BDsPNZ3zPyhlx/87broTwfW4HN0ssa iWGhr/bivQeTtmksvTLv6IzPAIQaME2PUVkfFkuRw1airjzZsMvbgT7a1TNM+pIh+HRUicCONv3 erQAclWQW7P54+AKpeLnbduanGp3yjHZkbxqB4R6qDavwyUEKvNgrIqtXyN9qDY55cwLA== X-Google-Smtp-Source: AGHT+IFZ1xd7sQWwSqEgDrOhd1QOeKfKOl61j1mgSLHxuIwA8LnoQwnClNeZUno3M5MV/uLXbJUPk6J9/DgSQ3Dm/p0= X-Received: by 2002:a05:6820:820:b0:65d:95d:2de2 with SMTP id 006d021491bc7-65f54f3701amr816111eaf.25.1767781987249; Wed, 07 Jan 2026 02:33:07 -0800 (PST) MIME-Version: 1.0 From: Stuart Campbell Date: Wed, 7 Jan 2026 21:32:56 +1100 X-Gm-Features: AQt7F2qmk4R9p5AJq2ZDh-mrAwC578WS3fv4A2xxmqlXiw5qkzxusuzZiMkweXs Message-ID: Subject: Unexpected modification of check constraint definition To: pgsql-general@postgresql.org Content-Type: multipart/alternative; boundary="0000000000006470030647c9d154" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000006470030647c9d154 Content-Type: text/plain; charset="UTF-8" Hi there, I noticed that check constraint definitions are sometimes rewritten/normalized on input, and I was hoping to understand that a little better. For instance, if I create this table with a check constraint: create table foo ( val varchar, constraint val_valid check (val in ('a','b','c')) ); and then dump the schema with pg_dump, it looks more like this: CREATE TABLE public.foo ( val character varying, CONSTRAINT val_valid CHECK (((val)::text = ANY ((ARRAY['a'::character varying, 'b'::character varying, 'c'::character varying])::text[]))) ); However, if I then recreate the schema from that dump, and then dump with pg_dump a second time, it ends up different again: CREATE TABLE public.foo ( val character varying, CONSTRAINT val_valid CHECK (((val)::text = ANY (ARRAY[('a'::character varying)::text, ('b'::character varying)::text, ('c'::character varying)::text]))) ); I'm working in a Ruby on Rails application where the schema is periodically dumped to a structure.sql file on disk. So, it would be convenient if the constraint definition was "stable" (otherwise, there's unnecessary noise in our version control history) Is it expected that the second form is rewritten into the third form? It seems a bit odd to see all the type casting going on, but maybe there is a good reason for that. (Maybe this is an issue with using varchar instead of text?) Regards, Stuart -- This communication and any attachments may contain confidential information and are intended to be viewed only by the intended recipients. If you have received this message in error, please notify the sender immediately by replying to the original message and then delete all copies of the email from your systems. --0000000000006470030647c9d154 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi there,

I noticed that che= ck constraint definitions are sometimes rewritten/normalized on input, and = I was hoping to understand that a little better.

F= or instance, if I create this table with a check constraint:

=
create table foo (
=C2=A0 val varchar,
=C2=A0 constraint val= _valid check (val in ('a','b','c'))
);

and then dump the schema with pg_dump, it looks = more like this:

CREATE TABLE public.foo (
=C2=A0 =C2=A0 val character varying,
=C2=A0 =C2=A0 CONSTRAINT val_v= alid CHECK (((val)::text =3D ANY ((ARRAY['a'::character varying, &#= 39;b'::character varying, 'c'::character varying])::text[])))
);

However, if I then recreate the schema from that dump, and then dump = with pg_dump a second time, it ends up different again:

CREATE TABLE public.foo (
= =C2=A0 =C2=A0 val character varying,
=C2=A0 =C2=A0 CONSTRAINT val_valid CHECK (((val)::text =3D ANY (A= RRAY[('a'::character varying)::text, ('b'::character varyin= g)::text, ('c'::character varying)::text])))
);

I'm workin= g in a Ruby on Rails application where the schema is periodically dumped to= a structure.sql file on disk. So, it would be convenient if the constraint= definition was "stable" (otherwise, there's unnecessary nois= e in our version control history)

Is it expected t= hat the second form is=C2=A0rewritten into the third form? It seems a bit o= dd to see all the type casting going on, but maybe there is a good reason f= or that. (Maybe this is an issue with using varchar instead of text?)
=

Regards,
Stuart

This communication and any attachments may contain confidential inform= ation and are intended to be viewed only by the intended recipients. If you= have received this message in error, please notify the sender immediately = by replying to the original message and then delete all copies of the email= from your systems.


--0000000000006470030647c9d154--