Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hS9YM-0004RI-Pq for pgsql-sql@arkaria.postgresql.org; Sun, 19 May 2019 00:19:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hS9YL-0007MA-C6 for pgsql-sql@arkaria.postgresql.org; Sun, 19 May 2019 00:19:49 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hS9YH-0006xG-J1 for pgsql-sql@lists.postgresql.org; Sun, 19 May 2019 00:19:49 +0000 Received: from ns-b.lerctr.org ([2001:470:1f0f:3ad::53:2] helo=thebighonker.lerctr.org) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hS9YE-0000Ka-6N for pgsql-sql@postgresql.org; Sun, 19 May 2019 00:19:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lerctr.org; s=ler2019; h=Message-ID:References:In-Reply-To:Subject:To:From:Date: Content-Transfer-Encoding:Content-Type:MIME-Version:Sender:Reply-To:Cc: 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=z3HvFMnXjSh0MtrHoWh2eZZewyUSz0st2zoRB197/i8=; b=G4RpD/2ieL+aZiBiBRuAk2Oxri b3/GHCgy9JafBgu8gDPHc9aUUEh/5Sb2C64RimTX0r9w6N4FM7O18SjAt4RCTESktxrMrU7ghenvY 07WLHwjZahyffC8nOPCvgu2Uv/mPRcB5BXgR8azqhfMVcOUj5/MAg4S1AnFCjW1uAAeGCCfMHamJa kqhOCotCwy9GW0nRYH2OAfNzVwiXiBLKIHzdgq+ndoWrc1oOOgKsGOw3gFUY/FKPF55aFtlH/Puy4 crXn5WMZ3aeX3oy+8iZQDOoHO0Pcnq5XvHZ0TjY3atTcpRH9AN6phzxSKILuBfokLYlaedCGG07PH 2bImtZ/Q==; Received: from thebighonker.lerctr.org ([2001:470:1f0f:3ad:bb:dcff:fe50:d900]:27930 helo=webmail.lerctr.org) by thebighonker.lerctr.org with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92 (FreeBSD)) (envelope-from ) id 1hS9Y6-000CPh-By for pgsql-sql@postgresql.org; Sat, 18 May 2019 19:19:34 -0500 Received: from 2600:1700:210:b180:3556:b7d:be69:4daa by webmail.lerctr.org with HTTP (HTTP/1.1 POST); Sat, 18 May 2019 19:19:34 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 18 May 2019 19:19:34 -0500 From: Larry Rosenman To: pgsql-sql@postgresql.org Subject: Re: create index on a jsonb timestamp field? In-Reply-To: <78a5d1232bb5ef5797a8ae6e1f23543f@lerctr.org> References: <78a5d1232bb5ef5797a8ae6e1f23543f@lerctr.org> Message-ID: X-Sender: ler@lerctr.org User-Agent: Roundcube Webmail/1.3.9 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 05/18/2019 5:53 pm, Larry Rosenman wrote: > I'm playing with DNSTAP (dnstap.info) data and loading it into a > database for analysis. > > when I try to create an index on the query_time field of the json > structure I get: > > ler=# select id,data->'message'->>'query_time' from dns_query limit 2; > id | ?column? > ----+----------------------------- > 2 | 2019-05-13T01:35:59.822984Z > 3 | 2019-05-13T01:35:59.829801Z > (2 rows) > > ler=# select id,(data->'message'->>'query_time')::timestamptz from > dns_query limit 2; > id | timestamptz > ----+------------------------------- > 2 | 2019-05-12 20:35:59.822984-05 > 3 | 2019-05-12 20:35:59.829801-05 > (2 rows) > > ler=# > > ler=# create index dns_query_time_idx on dns_query(((data -> 'message' > ->> 'query_time')::text::timestamptz)); > ERROR: functions in index expression must be marked IMMUTABLE > > Is there any easy way to do this? Or, what would the experts recommend > here? I found a work-around in making a column for query time, and populating that in an UPDATE/INSERT trigger, and then making an index on that. -- Larry Rosenman http://www.lerctr.org/~ler Phone: +1 214-642-9640 E-Mail: ler@lerctr.org US Mail: 5708 Sabbia Dr, Round Rock, TX 78665-2106