Re: ERROR: malformed record literal: "",DETAIL: Missing left parenthesis? - Mailing list pgsql-general

From Albe Laurenz
Subject Re: ERROR: malformed record literal: "",DETAIL: Missing left parenthesis?
Date
Msg-id D960CB61B694CF459DCFB4B0128514C206A3E0AF@exadv11.host.magwien.gv.at
Whole thread Raw
In response to ERROR: malformed record literal: "",DETAIL: Missing left parenthesis?  (Emi Lu <emilu@encs.concordia.ca>)
List pgsql-general
> A question about: ERROR:  malformed record literal: ""
> DETAIL:  Missing left parenthesis.
>
> Can someone tell me what cause the error?
>
> ========================
> Table z_drop;
>     Column    |          Type
> -------------+------------------------
>   run_date    | character varying(128)
>   adm_year    | character varying(4)
>   adm_sess    | character varying(1)
>   faculty     | character varying(128)
>   ac_cycle    | character varying(128)
>   deg_code    | character varying(128)
>   discipline  | character varying(128)
>   thesis      | character varying(128)
>   elig_stype  | character varying(128)
>   stud_source | character varying(128)
>   applied     | numeric
>   reviewed    | numeric
>   accepted    | numeric
>   confirmed   | numeric
>   registered  | numeric
>   hold        | numeric
>   forward     | numeric
>   refused     | numeric
>   cancelled   | numeric
>   other       | numeric
>   pending     | numeric
>
>
> PREPARE test(z_drop) AS  INSERT INTO z_drop VALUES  ($1, $2, $3,
> $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17,
> $18, $19, $20, $21) ;
>
>
>
> EXECUTE test('', '1', '1', '1', '1', '1', '1', '1', '1', '', 1, 1,
> '1', '0', '0', '0', '0', '0', '0', '0', '0') ;

Your EXECUTES expects one argument of type "z_drop", so it goes ahead
and tries to convert '' (the first argument) into something of type
"z_drop". This is a row type, so its string representation would have
to start with "(". It doesn't, hence the error message.

A correct (simplified) example would be:

CREATE TABLE z_drop (id integer PRIMARY KEY, val text);

PREPARE x(z_drop) AS INSERT INTO z_drop VALUES ($1.id, $1.val);
  (there is only one argument of type z_drop)

EXECUTE x(ROW(1, 'mama'));
  (with an explicit row constructor)
or
EXECUTE x((2, 'papa'));

Yours,
Laurenz Albe

pgsql-general by date:

Previous
From: jc9121
Date:
Subject: Re: PL/R download
Next
From: Craig Ringer
Date:
Subject: Re: failed archive command