pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: nehxby@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6529: Invalid numeric input syntax for 'select into' queries
Date: Wed, 21 Mar 2012 23:11:04 -0400
Message-ID: <16398.1332385864@sss.pgh.pa.us> (raw)
In-Reply-To: <E1S7SZe-00085R-BA@wrigleys.postgresql.org>
References: <E1S7SZe-00085R-BA@wrigleys.postgresql.org>

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



view thread (2+ messages)

Message-ID: <16398.1332385864@sss.pgh.pa.us>
Permalink:  ../16398.1332385864@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16398.1332385864@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, nehxby@gmail.com
  Subject: Re: BUG #6529: Invalid numeric input syntax for 'select into' queries
  In-Reply-To: <16398.1332385864@sss.pgh.pa.us>
  References: <E1S7SZe-00085R-BA@wrigleys.postgresql.org> <16398.1332385864@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox