Re: BUG #18929: After the view is created, executed query against the view definition, reported syntax error.

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: 707330139(at)qq(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org, PG Bug reporting form <noreply(at)postgresql(dot)org>
Subject: Re: BUG #18929: After the view is created, executed query against the view definition, reported syntax error.
Date: 2025-05-15 14:41:42
Message-ID: 349f86e9-6922-4fcc-9725-b8a6f0667bea@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 15/05/2025 07:04, PG Bug reporting form wrote:
> postgres=# \d+ limit_thousand_v_3
> View "public.limit_thousand_v_3"
> Column | Type | Collation | Nullable | Default | Storage | Description
> ----------+---------+-----------+----------+---------+---------+-------------
> thousand | integer | | | | plain |
> View definition:
> SELECT thousand
> FROM onek
> WHERE thousand < 995
> ORDER BY thousand
> FETCH FIRST NULL::bigint + 1::bigint ROWS WITH TIES;
> postgres=# SELECT thousand
> postgres-# FROM onek
> postgres-# WHERE thousand < 995
> postgres-# ORDER BY thousand
> postgres-# FETCH FIRST NULL::bigint + 1::bigint ROWS WITH TIES;
> ERROR: syntax error at or near "::"
> LINE 5: FETCH FIRST NULL::bigint + 1::bigint ROWS WITH TIES;
> ^

Agreed that's a bug. Attached is a simple patch to add parens to all
deparsed FETCH FIRST n ROWS WITH TIES expressions.

It would be nice to skip the parens for simple literals, but
unfortunately it's non-trivial to distinguish Consts that are printed as
simple literals from more complicated cases that are printed as
typecasts, like '123'::bigint. XMLEXISTS is another expression type that
takes a 'c_expr' in the the grammar, and it also just always adds the
parens.

I'll commit this fix, unless someone comes up with something more
sophisticated.

--
Heikki Linnakangas
Neon (https://neon.tech)

Attachment Content-Type Size
fix-with-ties-deparse.patch text/x-patch 1021 bytes

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-05-15 15:28:44 Re: BUG #18933: PostgreSQL fails to handle JOIN operation involving Empty Table
Previous Message Andrei Lepikhov 2025-05-15 14:26:42 Re: Postgres: Queries are too slow after upgrading to PG17 from PG15