0

I have a function in my postgresql database that get as an argument text : func1 (arg1 text);

I summon it many times somethimes with strings as arguments and some times as interger. I know that in oracle we can send int as an argument to a function that get string argument. Is it possible in postgresql ? I must use casting ?

1 Answer 1

2

In PostgreSQL, you do not have the same automatic casting like you have in Oracle. Instead, you have to cast explicitely:

select func1(134::text);
Sign up to request clarification or add additional context in comments.

6 Comments

There isnt any way to enable auto casting or something like that ?
No that I am aware of; but you can create a second function, same name, different parameter type, that calls the original one: create function func1(double precision) returns xxx as 'select func1(arg1::text)' language sql;
Yes I realized that, I searched for a solution that might help me handle many data types. Well, Thanks !
You can enable implicit cast in PostgreSQL. This will work: CREATE CAST (int AS text) WITH INOUT AS IMPLICIT;
Wow, I wish I had known that 2 years earlier!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.