pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Manuel Rigger <rigger.manuel@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: Generated column and string concatenation issue
Date: Wed, 10 Jul 2019 10:47:52 -0400
Message-ID: <17503.1562770072@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+u7OA6AD9OLziFW+io1HgN8q_XH0o1Y5RyufXYO5=0fnhG5zQ@mail.gmail.com>
References: <CA+u7OA6AD9OLziFW+io1HgN8q_XH0o1Y5RyufXYO5=0fnhG5zQ@mail.gmail.com>

Manuel Rigger <rigger.manuel@gmail.com> writes:
> Consider the following statement:

> CREATE TABLE t0(c0 TEXT GENERATED ALWAYS AS (('abc' || 1)) STORED); --
> unexpected: generation expression is not immutable

No, that's not a bug.  What you've got is "text || integer", which
requires an integer-to-text coercion, which isn't necessarily
immutable.  (Well, actually, integer-to-text is immutable.  But
the particular operator you're getting here is textanycat which
accepts anything on the RHS, so it has to be marked stable which
is our worst-case assumption for the stability of I/O conversions.
As an example, timestamp-to-text's results vary with the DateStyle
GUC so that one definitely isn't immutable.)

You could imagine different factorizations of this functionality
that might allow the specific RHS type to be taken into account,
but the actual details of how to make that happen aren't very
clear, and changing it might have other downsides.

Anyway the short answer is that you should have done

CREATE TABLE t0(c0 TEXT GENERATED ALWAYS AS (('abc' || '1')) STORED);

which would resolve as "text || text" which is immutable.
The explicit cast that you showed also dodges the problem
by not relying on textanycat.

			regards, tom lane





view thread (5+ messages)  latest in thread

Message-ID: <17503.1562770072@sss.pgh.pa.us>
Permalink:  ../17503.1562770072@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/17503.1562770072@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, rigger.manuel@gmail.com
  Subject: Re: Generated column and string concatenation issue
  In-Reply-To: <17503.1562770072@sss.pgh.pa.us>
  References: <CA+u7OA6AD9OLziFW+io1HgN8q_XH0o1Y5RyufXYO5=0fnhG5zQ@mail.gmail.com> <17503.1562770072@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox