Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g98Qy-0006so-5T for pgsql-general@arkaria.postgresql.org; Sun, 07 Oct 2018 12:45:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g98Qv-0000vl-JB for pgsql-general@arkaria.postgresql.org; Sun, 07 Oct 2018 12:45:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g98Qv-0000v4-9p for pgsql-general@lists.postgresql.org; Sun, 07 Oct 2018 12:45:17 +0000 Received: from ec2-34-255-138-49.eu-west-1.compute.amazonaws.com ([34.255.138.49] helo=zimbabwe.chezphil.org) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g98Qn-0000HG-3J for pgsql-general@lists.postgresql.org; Sun, 07 Oct 2018 12:45:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=chezphil.org mappendix.com; s=20171026; h=Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Subject:Date:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=F+r+Onuy2kxLI8RKcMYB6OgKMFvMxXSDSynWvE6Aduc=; b=C7uULQZb40pUHRoPyTHVNevek xiL+kT669ndjOZQEPKCL8eklMLCGUSRJhZG5Db9HGJpnOrgk2q9Vc2u2OyyIrcWdg/04J2EAnLR3e X/mNggepY2qRFKl8XDkCEg570jy4KcNpdc4HG5ajygPFo5MUnWkpXIa9W+Wa9YjPJKaG4=; Received: from localhost ([127.0.0.1] helo=chezphil.org) by zimbabwe.chezphil.org with esmtp (Exim 4.89) (envelope-from ) id 1g98Ql-0001oD-Pv for pgsql-general@lists.postgresql.org; Sun, 07 Oct 2018 13:45:07 +0100 Received: from localhost ([::ffff:127.0.0.1]) by zimbabwe with smtp (dmsmtpd 0.00001); Sun, 07 Oct 2018 13:45:07 +0100 From: "Phil Endecott" To: Cc: "Andrew Gierth" Date: Sun, 07 Oct 2018 13:45:07 +0100 Subject: Re: Text-indexing UTF-8 bytea, convert_from() immutability, null bytes... Message-ID: <1538916307632@dmwebmail.dmwebmail.chezphil.org> In-Reply-To: <87ftxia3l4.fsf@news-spur.riddles.org.uk> References: <87ftxia3l4.fsf@news-spur.riddles.org.uk> X-Mailer: Decimail Webmail 3alpha16 MIME-Version: 1.0 Content-Type: text/plain; format="flowed"; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Andrew, Thanks for your great reply. Andrew Gierth wrote: >>>>>> "Phil" == Phil Endecott writes: > Phil> As a hack I tried ALTER FUNCTION to make it immutable, > > A better approach is to wrap it in a function of your own which is > declared immutable, rather than hacking the catalogs: > > create function from_utf8(bytea) returns text language plpgsql immutable > as $$ begin return convert_from($1, 'UTF8'); end; $$; Thanks. I'm a bit surprised that it will allow me to declare a function immutable if it calls functions that aren't themselves immutable, but if it works... great. > Phil> Anyway: given the problem of creating a text search index over > Phil> bytea data that contains UTF-8 text, which may include oddities > Phil> like null bytes, what would you do? > > You can search for 0x00 in a bytea using position() or LIKE. What do you > want to do with values that contain null bytes? or values which you > think are supposed to be valid utf8 text but are not? As long as it doesn't crash I don't really care; it would be better if the text search worked for the valid parts of the text but even that isn't essential. I think I will probably need to do some more preprocessing on the data when I load it, at least to remove the null bytes. Regards, Phil.