Only superuser can define a leakproof function

My recent Ash postgres migration includes the following, and it’s causing the above error on Render.com because their managed postgres instance doesn’t allow for superuser access.

Should I remove this migration? I want to make sure it’s not going to cause issues elsewhere in the framework. Thanks.

 CREATE OR REPLACE FUNCTION timestamp_from_uuid_v7(_uuid uuid)
    RETURNS TIMESTAMP WITHOUT TIME ZONE
    AS $$
      SELECT to_timestamp(('x0000' || substr(_uuid::TEXT, 1, 8) || substr(_uuid::TEXT, 10, 4))::BIT(64)::BIGINT::NUMERIC / 1000);
    $$
    LANGUAGE SQL
    IMMUTABLE PARALLEL SAFE STRICT LEAKPROOF;

Not sure what tools you have for said instance. Can’t you just log in to some kind of console, enter psql and grant required privileges to non-superuser account?

I have used custom PostgreSQL’s functions many times and I do not imagine that somebody would prevent me from using so useful API.

If you ask me I understand why someone may not want superuser access for apps, but I don’t see why some privileges shouldn’t be allowed to grant for a desired postgres account … I would not limit your features because somebody blindly follows some security concepts.

At most you could make it configurable and disable some features in specific cases, but it shouldn’t affect everyone. Look that almost nobody knows my phone number. Should we now prevent apps from using phone numbers? In this case how we would do a phone calls? On the other side is me who does not have much phone calls as expected.

1 Like

It is only the LEAKPROOF keyword that requires super user access, and it is a small optimization. You can leave the function in but remove the word LEAKPROOF.

5 Likes

Interesting … Didn’t know about that. Huge :+1: for this!