pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #6529: Invalid numeric input syntax for 'select into' queries
2+ messages / 2 participants
[nested] [flat]
* BUG #6529: Invalid numeric input syntax for 'select into' queries
@ 2012-03-13 14:19 nehxby@gmail.com
2012-03-22 03:11 ` Re: BUG #6529: Invalid numeric input syntax for 'select into' queries Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: nehxby@gmail.com @ 2012-03-13 14:19 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 6529
Logged by: Maxim Turchin
Email address: nehxby@gmail.com
PostgreSQL version: 9.1.3
Operating system: Ubuntu 11.10
Description:
CREATE TYPE test_bug_type AS
(value numeric(15,2),
currency_id varchar);
CREATE TABLE test_bug_table (
id serial PRIMARY KEY,
test_field test_bug_type
);
INSERT INTO test_bug_table (test_field) VALUES ('(15.50,USD)');
DO
$$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;$$;
DROP TABLE test_bug_table;
DROP TYPE test_bug_type;
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #6529: Invalid numeric input syntax for 'select into' queries
2012-03-13 14:19 BUG #6529: Invalid numeric input syntax for 'select into' queries nehxby@gmail.com
@ 2012-03-22 03:11 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2012-03-22 03:11 UTC (permalink / raw)
To: nehxby@gmail.com; +Cc: pgsql-bugs
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2012-03-22 03:11 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-03-13 14:19 BUG #6529: Invalid numeric input syntax for 'select into' queries nehxby@gmail.com
2012-03-22 03:11 ` Tom Lane <tgl@sss.pgh.pa.us>
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