mrowe
mrowe

Reputation: 80

How to create a new function in PostgreSQL that is an alias to a different function?

I need to create an alias to the RANDOM() function that is provided by PostgreSQL. I would like to name the new function RAND(). The function takes no parameters and should do the same thing whether invoked using RANDOM() or RAND().

Software that I'm using supports different database backends. The RAND() function exists in MySQL, but in PostgreSQL the same function is called RANDOM(). Without needing to modify the software's code, I'd like to call RAND() from PSQL.

Upvotes: 1

Views: 602

Answers (1)

klin
klin

Reputation: 121784

Create a wrapper function:

create function rand()
returns float language sql as $$
    select random()
$$;

Upvotes: 4

Related Questions