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 1gMZeQ-0005x9-F0 for pgsql-general@arkaria.postgresql.org; Tue, 13 Nov 2018 14:26:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gMZeO-0007y2-0A for pgsql-general@arkaria.postgresql.org; Tue, 13 Nov 2018 14:26:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gMZeM-0007vp-Qv for pgsql-general@lists.postgresql.org; Tue, 13 Nov 2018 14:26:43 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gMZeF-0005p3-Gk for pgsql-general@postgresql.org; Tue, 13 Nov 2018 14:26:41 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 63149220F7; Tue, 13 Nov 2018 09:26:34 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 13 Nov 2018 09:26:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=E azw5e9JfJmPDlNxgNUx3gY90xZfJBqNFvdw0bEBvPM=; b=r6ZnJDybeDBtLTRLO O2cg1BxP7EXDDK2duczCehM87zgfNTdBIOs5icbwKZz7AI2AvgaugDoS7QmIsasq gdW81x3Mdn/IveNIFIIS8cEzKFb5C3R62Eo0H97BRlMM0syL/Tw+bJrkhkUhAoCW 33fWy99vJa92uWaZUvjSR5a9AHvdjW2OynpEFB12toiudKl+p8BlkWTCyiwKogBb qufw2dspDV/5bN7apJDwbQCm8ahND2c4f4DjBEZ62fHnQFJ0G5dDYY4A4CpIrUpl tav7yfUkgpieMpRCQAJH4s7uBgr9qM/Nexj82/4eegjRDfHWRX1KNAvuNGF5SYod fpyCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=Eazw5e9JfJmPDlNxgNUx3gY90xZfJBqNFvdw0bEBv PM=; b=OJ22fPgGIShQhrUtgs2zlFkLN35U9teKHV0jTNYInplOAjvYHHGMsiynm tkKNNb+PWE+wwZAEJCGPku2V8Tgaqx+631+Ck6MbghXy6Kl2SeFgFo0hI6e1p4jw F1AhddpTdY27EKPCRQPi0S1UOtlX/oBFigi4OSN/6ScvySKDmWgofPAzGuRCLmu5 EBAForBEmt3S6LvDK3zUpsVqxHpdBS+Qai93XObHoTqoWcWrjuWY87Y61l4DRcf/ OiNy2R4+9PTDYygwPV4i1Sgkigflp/MEKV3H5bz5/0MWuRjQKfu4w0vS3bB5QHD6 Qaa9iqMzYnKAeM2X5s7MuCI0m7nqQ== X-ME-Sender: X-ME-Proxy: Received: from [192.168.1.3] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 56B11E4307; Tue, 13 Nov 2018 09:26:33 -0500 (EST) Subject: Re: Plpgsql search_path issue going from 9.3 to 9.6 To: George Woodring , pgsql-general References: From: Adrian Klaver Message-ID: Date: Tue, 13 Nov 2018 06:26:32 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/13/18 5:17 AM, George Woodring wrote: > We are having an issue with one of our plpgsql functions after migrating > from 9.3 to 9.6.  The function works fine until you change the search path. > > psql (9.6.10) > Type "help" for help. > > woody=> select ticket_summary(8154); >                           ticket_summary > ------------------------------------------------------------------- >  {58451,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} > (1 row) > > woody=> set search_path to "iss-hackers", public; > SET > woody=> select ticket_summary(8154); > ERROR:  invalid input syntax for type timestamp with time zone: "woodring" Well the above is the base of the issue, the string 'woodring' is being used as a timestamp entry. Somewhere wires are getting crossed. In the function below you have: SELECT * INTO ticket FROM tickets WHERE ticketsid=tid; This is the only place where you do not schema qualify a table. Is there more then tickets table? > CONTEXT:  PL/pgSQL function ticket_summary(integer) line 11 at SQL statement > > It is confused which column is which after the change. > > The tables used by the function are: > public.tickets - A table with 3 child tables > iss-hackers.tickets - A view of public.tickets with a where clause. > public.followups - A table with 3 child tables. > > CREATE OR REPLACE FUNCTION ticket_summary(int4) RETURNS int8[] AS $$ >    DECLARE >       tid ALIAS FOR $1; >       cstate public.followups.state%TYPE := 1; >       ticket public.tickets%ROWTYPE; >       followup public.followups%ROWTYPE; >       summary int8[] := '{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}'; >       lastdate public.followups.date%TYPE; >    BEGIN >       SELECT * INTO ticket FROM tickets WHERE ticketsid=tid; >       IF NOT FOUND THEN >          return summary; >       END IF; >       lastdate := ticket.opendate; >       FOR followup IN SELECT * FROM public.followups WHERE > ticketsid=tid AND state IS NOT NULL ORDER BY date LOOP >          summary[cstate] := summary[cstate] + extract( EPOCH FROM > (followup.date - lastdate))::int; >          cstate := followup.state; >          lastdate := followup.date; >       END LOOP; >       summary[cstate] := summary[cstate] + extract( EPOCH FROM > (current_timestamp - lastdate))::int; >       RETURN summary; >    END; > $$ LANGUAGE plpgsql; > > I assume I can fix this by putting the function into each of the > schemas, but I thought I would ask opinions before doing so. > >  Thanks, > George Woodring > iGLASS Networks > www.iglass.net -- Adrian Klaver adrian.klaver@aklaver.com