1

How can I create function that accepts arguments of any type.

I can create function like this: CREATE FUNCTION test(anyelement,anyelement) ...

But when I call it, I have to present arguments of same type:

SELECT test(1,2); -- ok

But:

SELECT test('lalala',2); -- error

Can I create a function that will accept arguments of any type, then cast them to string and do something with this strings.

So, can I create function that will look like concat(str "any" [, str "any" [, ...] ])

UPD: updated second example

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
Yavanosta
  • 1,480
  • 3
  • 18
  • 27

1 Answers1

2

There is a simple alternative. Every type can be cast to text. You can just create a function:

CREATE FUNCTION test(text, text [,text [, ...]]) ...

And call it:

SELECT test('lalala'::text,2::text);

Just cast each argument to text explicitly.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228