Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 617941C84891 for ; Thu, 22 Mar 2012 00:11:19 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SAYQo-0004gG-LJ for pgsql-bugs@postgresql.org; Thu, 22 Mar 2012 03:11:19 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q2M3B4fr016399; Wed, 21 Mar 2012 23:11:04 -0400 (EDT) To: nehxby@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6529: Invalid numeric input syntax for 'select into' queries In-reply-to: References: Comments: In-reply-to nehxby@gmail.com message dated "Tue, 13 Mar 2012 14:19:38 -0000" Date: Wed, 21 Mar 2012 23:11:04 -0400 Message-ID: <16398.1332385864@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201203/159 X-Sequence-Number: 32720 nehxby@gmail.com writes: > [ test_bug_type is composite ] > $$DECLARE > test_bug_var test_bug_type; > BEGIN > SELECT test_field INTO test_bug_var FROM test_bug_table LIMIT 1; > --ERROR: invalid input syntax for type numeric: "(15.50,USD)" > --CONTEXT: PL/pgSQL function "inline_code_block" line 7 at SQL statement > > -- OR: > INSERT INTO test_bug_table (test_field) VALUES ('(35.80,EUR)') > RETURNING test_field INTO test_bug_var; > --ERROR: invalid input syntax for type numeric: "(35.80,EUR)" > > RAISE NOTICE 'Test %', test_bug_var; > END;$$; plpgsql is expecting the SELECT or RETURNING list to supply the components of the composite target variable separately. That's sometimes convenient and sometimes not so much, but I'm not sure we could change it without breaking an awful lot of peoples' functions. The way to deal with this when your source value is a composite column is to expand the source value into separate components, for instance SELECT (test_field).* INTO test_bug_var FROM test_bug_table LIMIT 1; INSERT INTO test_bug_table (test_field) VALUES ('(35.80,EUR)') RETURNING (test_field).* INTO test_bug_var; (The parentheses are necessary here because without them "test_field" would be syntactically a table name, not a column name.) regards, tom lane