Search code examples
sqlpostgresqldbeaver

DBeaver turns a list of attributes in a procedure into a string


I'm trying to write the attributes via a line break to make the procedure easy to read and edit, but, after saving the procedure, dbeaver auto-edits it, turning the attribute list in the procedure into a string.

This is a header of procedure that I wrote myself:

CREATE OR REPLACE PROCEDURE public.full_load(
    IN input_table_name VARCHAR, 
    IN target_table_name VARCHAR, 
    IN load_key_field VARCHAR, 
    IN load_id_field VARCHAR, 
    IN last_load_id_field VARCHAR, 
    IN valid_to_dttm_field VARCHAR, 
    IN valid_from_dttm_field VARCHAR, 
    IN paral INT DEFAULT 1
)

And this is how DBeaver automatically edited my procedure after saving it:

CREATE OR REPLACE PROCEDURE public.full_load(IN input_table_name character varying, IN target_table_name character varying, IN load_key_field character varying, IN load_id_field character varying, IN last_load_id_field character varying, IN valid_to_dttm_field character varying, IN valid_from_dttm_field character varying, IN paral integer DEFAULT 1)

It makes my code much worse to read and edit.

Is there a parameter in the Dbeaver settings that is responsible for disabling auto-editing of the procedure header?


Solution

  • When you inspect a routine you defined on the db, DBeaver probably just runs pg_get_function_arguments(). It doesn't recall how exactly the routine was defined down to comments and whitespace, but rather reconstructs a DDL-compatible list:

    pg_get_function_arguments ( func oid ) → text

    Reconstructs the argument list of a function or procedure, in the form it would need to appear in within CREATE FUNCTION (including default values).

    You can try it yourself:

    CREATE OR REPLACE PROCEDURE /*inline comment*/ public.full_load    (
        IN input_table_name VARCHAR, --end-of-line comment
         IN target_table_name VARCHAR,
        IN load_key_field VARCHAR,
        IN load_id_field VARCHAR,
        IN last_load_id_field VARCHAR,
        IN valid_to_dttm_field VARCHAR,
        IN valid_from_dttm_field VARCHAR,
          IN paral INT DEFAULT 1
    ) LaNguAge PlpgSql as --funky capitalization
    $$
    bEGin SeLeCT 'abc'/*inline*/           ;
    eND; --end of line comment
    $$;
    
    select pg_get_function_arguments('full_load'::regproc);
    
    pg_get_function_arguments
    IN input_table_name character varying, IN target_table_name character varying, IN load_key_field character varying, IN load_id_field character varying, IN last_load_id_field character varying, IN valid_to_dttm_field character varying, IN valid_from_dttm_field character varying, IN paral integer DEFAULT 1

    You can also see this in psql meta-command \ef full_load: body is saved as-is and recalled in full while the rest is only reconstructed:

    CREATE OR REPLACE PROCEDURE public.full_load(IN input_table_name character varying, IN target_table_name character varying, IN load_key_field character varying, IN load_id_field character varying, IN last_load_id_field character varying, IN valid_to_dttm_field character varying, IN valid_from_dttm_field character varying, IN paral integer DEFAULT 1)
     LANGUAGE plpgsql
    AS $procedure$
    bEGin SeLeCT 'abc'/*inline*/           ;
    eND; --end of line comment
    $procedure$
    

    You're supposed to save your code as .sql script file somewhere if you wish to retain details like that. Otherwise, PostgreSQL will only try to remember the routine body in detail, but the signature (name, arguments, settings) will be stripped from insignificant tokens like comments and whitespace, including the newlines and indentation that you lost, plus capitalization.