Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Support for SET configuration_parameter { TO value | = value | FROM CURRENT } in Function Definition Syntax #3054

Open
mpyw opened this issue Aug 18, 2024 · 2 comments

Comments

@mpyw
Copy link

mpyw commented Aug 18, 2024

Description:

I would like to request a new feature in Atlas HCL to support the following SQL syntax within function definitions:

-- Create "pg_try_advisory_lock_timeout" function
CREATE FUNCTION "public"."pg_try_advisory_lock_timeout"("key" text, "timeout" text)
RETURNS boolean
SET lock_timeout FROM CURRENT
LANGUAGE plpgsql
AS $$
  BEGIN
    EXECUTE format('SET SESSION lock_timeout TO %L;', timeout);
    PERFORM pg_advisory_lock(hashtext(key));
    RETURN true;
  EXCEPTION
    WHEN lock_not_available OR deadlock_detected THEN RETURN false;
  END
$$;

In this example, the function temporarily sets the advisory lock timeout and restores the previous value upon exit. The syntax SET ... FROM CURRENT is used to revert the session's configuration back to its original state, making it essential for scenarios where temporary session configurations are needed.

However, the current version of Atlas HCL does not seem to support the SET ... FROM CURRENT syntax within function definitions, which is not limited to lock_timeout but applies to any session configuration.

Adding support for this syntax in function definitions would significantly enhance Atlas's ability to manage and manipulate temporary session settings efficiently.

Thank you for considering this request.

@mpyw
Copy link
Author

mpyw commented Aug 18, 2024

PostgreSQL: Documentation: 16: CREATE FUNCTION

CREATE [ OR REPLACE ] FUNCTION
    name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr ] [, ...] ] )
    [ RETURNS rettype
      | RETURNS TABLE ( column_name column_type [, ...] ) ]
  { LANGUAGE lang_name
    | TRANSFORM { FOR TYPE type_name } [, ... ]
    | WINDOW
    | { IMMUTABLE | STABLE | VOLATILE }
    | [ NOT ] LEAKPROOF
    | { CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT }
    | { [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER }
    | PARALLEL { UNSAFE | RESTRICTED | SAFE }
    | COST execution_cost
    | ROWS result_rows
    | SUPPORT support_function
    | SET configuration_parameter { TO value | = value | FROM CURRENT }
    | AS 'definition'
    | AS 'obj_file', 'link_symbol'
    | sql_body
  } ...

Here -> | SET configuration_parameter { TO value | = value | FROM CURRENT }

@mpyw
Copy link
Author

mpyw commented Aug 18, 2024

Note: It is important to mention that FROM CURRENT does not always refer to the actual current session state. Unfortunately, it refers to the state at the time the CREATE FUNCTION command is executed. Despite this limitation, using the syntax like SET lock_timeout TO '0' is still very meaningful, and therefore, I strongly request that this syntax be supported at a minimum.

@mpyw mpyw changed the title Feature Request: Support for SET ... FROM CURRENT in Function Definition Syntax Feature Request: Support for SET configuration_parameter { TO value | = value | FROM CURRENT } in Function Definition Syntax Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant