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 1hS8DN-0000vy-Vv for pgsql-sql@arkaria.postgresql.org; Sat, 18 May 2019 22:54:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hS8DL-0005bp-L1 for pgsql-sql@arkaria.postgresql.org; Sat, 18 May 2019 22:54:03 +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 1hS8DG-0005bh-JN for pgsql-sql@lists.postgresql.org; Sat, 18 May 2019 22:54:03 +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 1hS8D3-0006wG-4X for pgsql-sql@postgresql.org; Sat, 18 May 2019 22:53:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lerctr.org; s=ler2019; h=Message-ID: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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=fFUxZFZ/ft9pqvMM5Zrh+ClRQ7YlFEUm8j+0LhF0ttw=; b=v2cspGNSjkRuZXJaRfr4loaXgK vBqC9jAzWnY0VitYnTaR8WcZU0aZKN7o1H6h91o9V3rfEHL7dbg5dt8WzZLv4wKSpDv4N+aNj7wN6 whbIgBBQc91qGqYHbYcLaQMMgN2NL0hPmgUPJ2Ydi1XKM7luAMOyBOn661ZGFKyHdjGG5oFkcJhk0 83P1/9xIRBcra0iW05oPXCgw4HQJV+yIyZKdMBgq56q2TYQBaS6lZKiXv9iUepptTt869CXnr1uNx +mNhpRL+584zqxnOZLJmPT/wZ6+kABuz5p0/FUeDzBcr3nmGx+C1hbSaLJjxMbeKYCZx5vU93huqN Wcoo2oqQ==; Received: from thebighonker.lerctr.org ([2001:470:1f0f:3ad:bb:dcff:fe50:d900]:64238 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 1hS8Cu-000APp-2M for pgsql-sql@postgresql.org; Sat, 18 May 2019 17:53:36 -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 17:53:35 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 18 May 2019 17:53:35 -0500 From: Larry Rosenman To: pgsql-sql@postgresql.org Subject: create index on a jsonb timestamp field? Message-ID: <78a5d1232bb5ef5797a8ae6e1f23543f@lerctr.org> 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 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? -- 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