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 1fGnYQ-0000Kc-0m for pgsql-general@arkaria.postgresql.org; Thu, 10 May 2018 15:32:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fGnYN-0003Ob-ID for pgsql-general@arkaria.postgresql.org; Thu, 10 May 2018 15:32:23 +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 1fGnYN-0003OS-9e for pgsql-general@lists.postgresql.org; Thu, 10 May 2018 15:32:23 +0000 Received: from 23-25-19-49-static.hfc.comcastbusiness.net ([23.25.19.49] helo=jeeves.wrkhors.com) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fGnYJ-0002Ux-Bu for pgsql-general@lists.postgresql.org; Thu, 10 May 2018 15:32:22 +0000 Received: from wrkhors.com (localhost [127.0.0.1]) by jeeves.wrkhors.com (Postfix) with ESMTP id 02AE24B3C5; Thu, 10 May 2018 10:43:17 -0500 (CDT) Date: Thu, 10 May 2018 10:30:41 -0500 From: Steven Lembark To: pgsql-general@lists.postgresql.org Cc: lembark@wrkhors.com Subject: Selecting strict, immutable text for a composite type. Message-ID: <20180510103041.472408bb@wrkhors.com> Organization: Workhorse Computing MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Trying to find specific doc's. Lots of people asking similar quesitons told to work around it different ways. Is there any specific doc on how to create a default operator class for a given composite type with any examples of minimal working code to access the pieces and convert them to text? I have produced quite a variety of botched syntax on this trying to see which shit sticks to the wall... just one working example would be most apprecated. As an example: Say I wanted to use domains for latitude and longitude that enforce +/- 180 and +/- 90 and let's say for the moment that float is an approprite base type (though it might be real or numeric, that is a seprate question). I can combine the domains into a single type with a lat and lng elemnt. So far so good. Q: What is the syntax for a strict, immutable function in SQL that returns text suitable for use with either creating a "select *" view or a GIST index? I believe my mistake is somewhere in the number and placement of paren's but I have tried quite a few combinations based on various postings without success. Rather than detail them I'm just asking for a reference to one working example for any roughly similar composite type. thanks Example: /* * this much works. */ create domain longitude_d as float not null check ( VALUE >= -180.0::float and VALUE <= +180.0::float ); create domain latitude_d as float not null check ( value >= -90.0::float and value <= +90.0::float ); create type lat_lng_t as ( lng longitude_d, lat latitude_d ); /* * someting about this does not work. * the signiture seems reasonable, * as does the returns ... as. * * Q: What is the correct syntax for * select ... ? */ create or replace function lat_lng_text ( lat_lng_t ) returns text language sql strict immutable as $$ select ($1).lng::text || '-' || ($1).lat::text $$ -- Steven Lembark 1505 National Ave Workhorse Computing Rockford, IL 61103 lembark@wrkhors.com +1 888 359 3508