pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Matt Magoffin <postgresql.org@msqr.us>
Cc: pgsql-bugs@postgresql.org, Teodor Sigaev <teodor@sigaev.ru>
Subject: Re: tsvector_update_trigger() fails in 9.6 on character(2) column
Date: Wed, 08 Mar 2017 22:34:46 -0500
Message-ID: <24975.1489030486@sss.pgh.pa.us> (raw)
In-Reply-To: <016F132F-67E0-4576-A388-A5FABAC89235@msqr.us>
References: <016F132F-67E0-4576-A388-A5FABAC89235@msqr.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Matt Magoffin <postgresql.org@msqr.us> writes:
> I am migrating a 9.3 database to 9.6, and came across what looks like a possible regression somewhere in tsvector_update_trigger() when passed a column of type character. The following works in 9.3:

> CREATE TABLE public.foo (
>   foo_id integer NOT NULL,
>   country character(2) NOT NULL,
>    fts tsvector,
>   CONSTRAINT foo_pk PRIMARY KEY (foo_id)
> );
> CREATE TRIGGER maintain_fts
>   BEFORE INSERT OR UPDATE
>   ON public.foo
>   FOR EACH ROW
>   EXECUTE PROCEDURE tsvector_update_trigger('fts', 'pg_catalog.english', 'country');

> INSERT INTO public.foo (foo_id, country) VALUES (1, 'US');

> But the same thing in 9.6 results in :

> ERROR: column "country" is not of a character type

This is a consequence of commit 9acb9007de30b3daaa9efc16763c3bc6e3e0a92d,
which replaced a handwritten type-compatibility check with an
IsBinaryCoercible() test.  Since char(n) is in fact not binary-coercible
to text, IsBinaryCoercible() rejects this case.  (A char(n)-to-text cast
normally involves a function that strips trailing blanks.)

If we're willing to assume that tsvector never cares about trailing blanks
in its input string, then we could just allow the case, along the lines of

-       if (!IsBinaryCoercible(SPI_gettypeid(rel->rd_att, numattr), TEXTOID))
+       if (!IsBinaryCoercible(SPI_gettypeid(rel->rd_att, numattr), TEXTOID) &&
+           !IsBinaryCoercible(SPI_gettypeid(rel->rd_att, numattr), BPCHAROID))

Not entirely sure that it's worth the trouble, as this seems like a rather
strange use-case to me.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (3+ messages)  latest in thread

Message-ID: <24975.1489030486@sss.pgh.pa.us>
Permalink:  ../24975.1489030486@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/24975.1489030486@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, postgresql.org@msqr.us, teodor@sigaev.ru
  Subject: Re: tsvector_update_trigger() fails in 9.6 on character(2) column
  In-Reply-To: <24975.1489030486@sss.pgh.pa.us>
  References: <016F132F-67E0-4576-A388-A5FABAC89235@msqr.us> <24975.1489030486@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