polymorphic functions and domains
От | TJ O'Donnell |
---|---|
Тема | polymorphic functions and domains |
Дата | |
Msg-id | 47584418.1020204@acm.org обсуждение исходный текст |
Ответы |
Re: polymorphic functions and domains
|
Список | pgsql-sql |
When I define two polymorpic functions, one taking varchar and one bytea, there seems to be no confusion choosing the varchar version when called with the untyped literal 'abc'. I really want two polymorphic functions, one taking a domain data type using varchar and one bytea. In that case, postgres complains that it cannot decide which one to use when called with the untyped literal 'abc'. I thought I might could force the domain varchar version to be chosen by casting the domain as varchar, but this does not help. The situation is explained in SQL below. Can someone help me get qtest('abc') to use the qtest(astring) function without having to explicitly cast 'abc'::astring; I'm using 8.2.5 and Linux.k Thanks, TJ O'Donnell www.gnova.com ---------------------------------------------- Drop Function ztest(Character Varying); Drop Function ztest(bytea); Drop Function qtest(astring); Drop Function qtest(Bytea); Drop Cast (astring as Character Varying); Drop Domain astring; Create Or Replace Function ztest(Character Varying) Returns Integer As $EOSQL$ Select length($1); $EOSQL$ Language SQL; Create Or Replace Function ztest(Bytea) Returns Integer As $EOSQL$ Select -(length($1)); $EOSQL$ Language SQL; Select ztest('abc'::Character Varying); -- worked as expected Select ztest('abc'::Bytea); -- worked as expected Select ztest('abc'); -- worked as expected Create Domain astring as Character Varying; Create Or Replace Function qtest(astring) Returns Integer As $EOSQL$ Select length($1); $EOSQL$ Language SQL; Create Or Replace Function qtest(Bytea) Returns Integer As $EOSQL$ Select -(length($1)); $EOSQL$ Language SQL; Select qtest('abc'::astring); -- worked as expected Select qtest('abc'::Bytea); -- worked as expected Select qtest('abc'); -- why did this not cause qtest(astring) to be chosen? Create Cast (astring As Character Varying) Without Function As Implicit; Select qtest('abc'); -- why did this not force qtest(astring) to be chosen?
В списке pgsql-sql по дате отправления: