pretty_bool in pg_get_constraintdef has no effect since pg >= 9

From: eli(dot)mach(at)mailbox(dot)org
To: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: pretty_bool in pg_get_constraintdef has no effect since pg >= 9
Date: 2020-02-25 12:56:22
Message-ID: 490036036.13996.1582635382921@office.mailbox.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello,

since postgres 9, `pg_get_constraintdef(cons.oid, pretty_bool)` does not work as expected. The result is always in "pretty"-format (with newlines), regardless of whether `pretty_bool` is true or false. Calling `pg_get_constraintdef(constraint_oid)` without `pretty_bool`, also returns "pretty"-format.

Test with:

```
CREATE TABLE tbl (
id int NOT NULL DEFAULT 0
,CHECK
(
CASE
WHEN id < 0 THEN false
WHEN id >= 0 THEN true
END
)
);

SELECT cons.conname as name, pg_get_constraintdef(cons.oid, false) as src FROM pg_catalog.pg_constraint cons WHERE cons.conrelid IN (SELECT oid from pg_class WHERE relname='tbl') AND cons.contype = 'c';
```

Result on postgres 8:
```
CHECK (CASE WHEN (id < 0) THEN false WHEN (id >= 0) THEN true ELSE NULL::boolean END)
```

Result on postgres >= 9:
```
CHECK (
CASE
WHEN (id < 0) THEN false
WHEN (id >= 0) THEN true
ELSE NULL::boolean
END)
```

I'm migrating from postgres 8 to 11 and a sqlalchemy script throws a warning "SAWarning: Could not parse CHECK constraint text" because there a no newlines expected in `re.match(r"^CHECK *\((.+)\)( NOT VALID)?$", src)`.

Greetings,
elim.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Daniel Gustafsson 2020-02-25 13:30:17 Re: pretty_bool in pg_get_constraintdef has no effect since pg >= 9
Previous Message Daniel Gustafsson 2020-02-25 09:28:31 Re: BUG #16274: Repeated Libraries in Mac