Skip to content

pl/pgsql "Run SQL" over agressive #530

@Indribell

Description

@Indribell
  • OS: Debian
  • Database Type: PostgreSQL

A plpgSQL function with the following content in the database:

DROP FUNCTION IF EXISTS fn_change_user_name;

CREATE OR REPLACE FUNCTION public.fn_change_user_name(p_user_id integer, p_name text)
RETURNS vw_user
LANGUAGE plpgsql
AS $function$
UPDATE public.user set u_firstname = p_name where id = p_user_id;
SELECT * FROM vw_user WHERE id = p_user_id; 
$function$

The plugin will show

**> Run SQL**
DROP FUNCTION IF EXISTS fn_change_user_name;

**> Run SQL**
CREATE OR REPLACE FUNCTION public.fn_change_user_name(p_user_id integer, p_name text)
RETURNS vw_user
LANGUAGE plpgsql
AS $function$
UPDATE public.user set u_firstname = p_name where id = p_user_id;
**> Run SQL**
SELECT * FROM vw_user WHERE id = p_user_id; 
**> Run SQL**
$function$

Because it seems to only check if a SQL command ends with dot comma. But pl/pgsql functions are inside function blocks that are indicated with $$ for start, and $$ for end. Or named $name$ for start and $name$ for end.

Expected result:

**> Run SQL**
DROP FUNCTION IF EXISTS fn_change_user_name;

**> Run SQL**
CREATE OR REPLACE FUNCTION public.fn_change_user_name(p_user_id integer, p_name text)
RETURNS vw_user
LANGUAGE plpgsql
AS $function$
UPDATE public.user set u_firstname = p_name where id = p_user_id;
SELECT * FROM vw_user WHERE id = p_user_id; 
$function$

In other words, SQL block recognition is missing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions