© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
2 replies
Tobi

Are SQL injections in non EXECUTE rpc functions possible?

Do I understand it correct that SQL injections are NOT possible if I do NOT use the "execute keyword"?

Like this should be safe:

CREATE OR REPLACE FUNCTION public.search_user(
    search_term text
)
    RETURNS table
            (
                id         uuid,
                first_name text,
                last_name  text,
                username   text
            )
    LANGUAGE plpgsql
    SECURITY INVOKER
AS
$$
BEGIN
    RETURN QUERY
        SELECT
            id,
            first_name,
            last_name,
            username
        FROM
            profiles
        WHERE
            first_name = search_term;
END
$$;
CREATE OR REPLACE FUNCTION public.search_user(
    search_term text
)
    RETURNS table
            (
                id         uuid,
                first_name text,
                last_name  text,
                username   text
            )
    LANGUAGE plpgsql
    SECURITY INVOKER
AS
$$
BEGIN
    RETURN QUERY
        SELECT
            id,
            first_name,
            last_name,
            username
        FROM
            profiles
        WHERE
            first_name = search_term;
END
$$;


But this is not safe?:
CREATE OR REPLACE FUNCTION public.search_user(
    search_term text
)
    RETURNS table
            (
                id         uuid,
                first_name text,
                last_name  text,
                username   text
            )
    LANGUAGE plpgsql
    SECURITY INVOKER
AS
$$
BEGIN
    RETURN QUERY ***EXECUTE***
        SELECT
            id,
            first_name,
            last_name,
            username
        FROM
            profiles
        WHERE
            first_name = search_term;
END
$$;
CREATE OR REPLACE FUNCTION public.search_user(
    search_term text
)
    RETURNS table
            (
                id         uuid,
                first_name text,
                last_name  text,
                username   text
            )
    LANGUAGE plpgsql
    SECURITY INVOKER
AS
$$
BEGIN
    RETURN QUERY ***EXECUTE***
        SELECT
            id,
            first_name,
            last_name,
            username
        FROM
            profiles
        WHERE
            first_name = search_term;
END
$$;
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

where are RPC functions logs?
SupabaseSSupabase / help-and-questions
4mo ago
Securing Helper Functions in RPC
SupabaseSSupabase / help-and-questions
4d ago
Is it possible to execute Functions on a schedule?
SupabaseSSupabase / help-and-questions
4y ago
Functions defined in the migrations are not found in the seed.sql
SupabaseSSupabase / help-and-questions
4y ago