In my PostgreSQL 9.6 database, I have a composite type, let's call that type
widget. I have a PL/pgSQL* function called
text_to_widget that parses textual representations of widgets to
widget values, and I have an implicit cast that calls this function:
CREATE CAST (text AS widget) WITH FUNCTION text_to_widget(text) AS IMPLICIT;
My cast is working well from variables or table values, but when I try to use the cast (either implicitly or explicitly) from string literals, I get an error:
postgres=# select 'my widget value'::widget; ERROR: malformed record literal: "" LINE 1: select 'my widget value'::widget; ^ DETAIL: Missing left parenthesis.
If I explicitly cast my string literal as text first, then it works fine:
postgres=# select 'my widget value'::text::widget; widget ------------------- (my,widget,value) (1 row)
I'm just confused why Postgres is trying to parse my string literal as a record before passing it to my cast, and if there's a way to make it stop doing that.
* Note that this database is hosted in AWS RDS, so I can't use a C function for the cast.