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 1iJjXy-0003lz-QJ for pgsql-bugs@arkaria.postgresql.org; Sun, 13 Oct 2019 19:28:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iJjUP-0000qY-J6 for pgsql-bugs@arkaria.postgresql.org; Sun, 13 Oct 2019 19:25:13 +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 1iJjT4-0000pg-Nl for pgsql-bugs@lists.postgresql.org; Sun, 13 Oct 2019 19:23:50 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJjT1-0008QU-HW for pgsql-bugs@lists.postgresql.org; Sun, 13 Oct 2019 19:23:50 +0000 Received: by mail-wr1-x442.google.com with SMTP id o18so17146723wrv.13 for ; Sun, 13 Oct 2019 12:23:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=6qKzwm98RiTJJZOfKAORGnXMTlj3195btlcLm6jqDwY=; b=tVDcJeVnV0WRqSLPPqsxG4JnVbeFPlbOsx7go55PSMQ+kF0uKnCShw87oIdpBhgicD PZ+YilOALonSaYGZL6XCcK+xENwpi2IlhkuIF8WZpXSpFPqYCjLk8h88nhOGqp8x5s3w m9X0iB5R1yJ+HqiIrTbod7D1/krZKoSGeMC7fvw3RvPEkmuOOW+bbWU4+qa0L9f4ihur uumgqCjIy3ozI5xIKjSHPvGvKemLRxo/+mdz2bRjnedlQy5FBNQe97IPYXDbsAvFaCVP 9J3HQg9xO4uOlB51GL9y9IvKfx6VaFYP3LMhWs2QwpF183SurMM1K7F5gNmBumItOOZp Jbdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=6qKzwm98RiTJJZOfKAORGnXMTlj3195btlcLm6jqDwY=; b=ejHCxQfglQX+9pstzqb7uOZeQ2qmQf5QyFN/tIUiSUPpMi7Nlbb98cwG1rxd2jGlEa YrR+yNA66UNnMH1VCaC8BwM5L4mlIxwWInsrVMp5LwJR+ydrmf4yZhYHGcAxjRcHMYZf d4lMVLdidpNQFOsh9HgzxtY77mPZ1kSvdMOeN89YUm79exYBtf0Nr3q1puNzGa6Y3zP8 so4dc/3P45esz7pWT8cpvj8H412j5JplUylSE4buk9lCkEv/9ofG0tEqYbWPrbOW2/4w VR23u/xrpj5u6Ccju/z8FdX5nh7Mq1ts1GHzXvefcQxPY8XZKBfzksj/ucumJcrsOa+C SvPw== X-Gm-Message-State: APjAAAU3otPHfS7PMe3p53UZxKW/JTtW8ZniTjuu8P92BCE51wcoWCGh JMfJ8vnEaXwkLwchl1Ef5RgJ9A== X-Google-Smtp-Source: APXvYqx0834+gr00DnLRY5AIcQ1dAoxCu4NZL/ZXk1dcKIjvnGc850B3SJMgZnE2acsm1f9fUIPdnw== X-Received: by 2002:adf:9c81:: with SMTP id d1mr21817989wre.238.1570994626034; Sun, 13 Oct 2019 12:23:46 -0700 (PDT) Received: from localhost (ip-86-49-253-183.net.upcbroadband.cz. [86.49.253.183]) by smtp.gmail.com with ESMTPSA id o9sm22269872wrh.46.2019.10.13.12.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2019 12:23:41 -0700 (PDT) Date: Sun, 13 Oct 2019 21:23:40 +0200 From: Tomas Vondra To: "McLaughlin, Michael" Cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: ERROR: invalid input syntax for integer: "0A000" Message-ID: <20191013192340.yxdekiiftlyosr6h@development> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, Oct 13, 2019 at 05:44:25PM +0000, McLaughlin, Michael wrote: >Code including test: > >-- Transaction Management Example. >DROP PROCEDURE IF EXISTS testing; > >-- Transaction Management Example. >CREATE OR REPLACE PROCEDURE testing >( IN pv_one VARCHAR(30) >, IN pv_two VARCHAR(10)) AS >$$ >DECLARE > /* Declare error handling variables. */ > err_num INTEGER; > err_msg INTEGER; >BEGIN > /* Create a SAVEPOINT as a starting point. */ > SAVEPOINT starting_point; > > /* Log actual parameter values. */ > INSERT INTO msg VALUES (pv_one||'.'||pv_two); > > /* Commit the series of inserts. */ > COMMIT; > >EXCEPTION > WHEN OTHERS THEN > err_num := SQLSTATE; > err_msg := SUBSTR(SQLERRM,1,100); > RAISE NOTICE 'Trapped Error: %', err_msg; >END >$$ LANGUAGE plpgsql; > >do $$ >DECLARE > lv_one VARCHAR(30) := 'INDIVIDUAL'; > lv_two VARCHAR(19) := 'R11-514-34'; >BEGIN > RAISE NOTICE '[%]', lv_one; > RAISE NOTICE '[%]', lv_two; > CALL testing( pv_one := lv_one, pv_two := lv_two ); >END >$$; > >SELECT * FROM msg; > >Running the code: > >videodb=> \i twoflat.sql >DROP PROCEDURE >CREATE PROCEDURE >psql:twoflat.sql:58: NOTICE: [INDIVIDUAL] >psql:twoflat.sql:58: NOTICE: [R11-514-34] >psql:twoflat.sql:58: ERROR: invalid input syntax for integer: "0A000" >CONTEXT: PL/pgSQL function testing(character varying,character varying) line 17 at assignment >SQL statement "CALL testing( pv_one := lv_one, pv_two := lv_two )" >PL/pgSQL function inline_code_block line 8 at CALL > comment >--------- >(0 rows) > It's generally a good idea to mention which PostgreSQL version you're on (I'll assume 12.0), and what the expected behavior is ... Anyway, there's a couple of bugs in your code: 1) SQLSTATE is not an integer, it's a code describing the state. so you have to change the err_num variable to text or something. 2) After fixing that, you'll get 0A000 sqlstate, which means "feature not supported" [1] with the explanation that you've used unsupported command - in this case savepoint. That's not supported in procedures, unfortutately. 3) After removing the savepoint, you'll get another failure because the exception block defines a subtransaction, which makes it impossible to perform a commit in the procedure. Unfortunately, these are limitations in the current implementation of stored procedures. Some of that may be improved in future releases, but at this point it's working as expected. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services