Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

fix to use pg_get_functiondef() #12

Conversation

antonov-impulsm
Copy link

fix to use pg_get_functiondef() in "Scripts=>CREATE Script".

pg_get_functiondef() -- less wrong

Andrej Antonov (impulsm.work) added 2 commits December 7, 2015 22:30
@ghost
Copy link

ghost commented Dec 7, 2015

Hi! Could you send this pull request as patch to pgadmin-hackers@postgresql.org?

@ghost
Copy link

ghost commented Dec 7, 2015

BTW

pg_get_functiondef() -- less wrong

what's wrong with this function? :)

@antonov-impulsm
Copy link
Author

@olshevskiy87 > what's wrong with this function? :)

ok. a few examples:

example "A"

write function:

CREATE FUNCTION test123()
 RETURNS TABLE(my_col text) 
 LANGUAGE plpgsql
AS $xxx$
BEGIN

my_col := 'abc';
RETURN NEXT;

my_col := 'def';
RETURN NEXT;

END;
$xxx$;

--SELECT * FROM test123();

pgAdmin3 transforming it to function:

-- Function: test123()

-- DROP FUNCTION test123();

CREATE OR REPLACE FUNCTION test123()
  RETURNS SETOF text AS
$BODY$
BEGIN

my_col := 'abc';
RETURN NEXT;

my_col := 'def';
RETURN NEXT;

END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
  ROWS 1000;
ALTER FUNCTION test123()
  OWNER TO postgres;

and of course with error:

ERROR:  "my_col" is not a known variable
LINE 10: my_col := 'abc';
         ^

********** Error **********

ERROR: "my_col" is not a known variable
SQL state: 42601
Character: 129

example "B"

CREATE FUNCTION test234(arr text[] DEFAULT ARRAY['sss', 'ddd'])
 RETURNS SETOF text
 LANGUAGE plpgsql
AS $xxx$
DECLARE
  r record;
BEGIN

FOR r IN SELECT UNNEST(arr) LOOP
  RETURN NEXT r.unnest;
END LOOP;

END;
$xxx$;

--SELECT * FROM test234();

pgAdmin3 transforming it to function:

-- Function: test234(text[])

-- DROP FUNCTION test234(text[]);

CREATE OR REPLACE FUNCTION test234(arr text[] DEFAULT ARRAY['sss'::text)
  RETURNS SETOF text AS
$BODY$
DECLARE
  r record;
BEGIN

FOR r IN SELECT UNNEST(arr) LOOP
  RETURN NEXT r.unnest;
END LOOP;

END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
  ROWS 1000;
ALTER FUNCTION test234(text[])
  OWNER TO postgres;

...with error:

ERROR:  syntax error at or near ")"
LINE 5: ...PLACE FUNCTION test234(arr text[] DEFAULT ARRAY['sss'::text)
                                                                      ^
********** Error **********

ERROR: syntax error at or near ")"
SQL state: 42601
Character: 137

other minor discomfort

words -- VOLATILE, COST 100, ROWS 1000 -- are extra (unnecessary, redundant).

@ghost
Copy link

ghost commented Dec 8, 2015

ok. a few examples:

but this sql code was generated by pgadmin, isn't it? I thought you are talking about native postgres function pg_get_functiondef() )
I would advise you to copy the previous comment to pgadmin-hackers@postgresql.org

@antonov-impulsm
Copy link
Author

but this sql code was generated by pgadmin, isn't it?
I thought you are talking about native postgres function pg_get_functiondef()

sorry for my ambiguity message..

yes. my examples -- about pgadmin-generation (without pg_get_functiondef() )

I wanted to say: I do not know about bad sides of pg_get_functiondef() , but if they exists -- I think them less then bad sides of original-pgadmin-generation .

I would advise you to copy the previous comment to pgadmin-hackers@postgresql.org

yes. i copied (just now)

olshevskiy87 and others added 2 commits December 14, 2015 10:33
…negation,

because type of the variable is wxstring. Also I added the Trim() function before
check if function definition is empty or not.
@repo-lockdown
Copy link

repo-lockdown bot commented Jun 17, 2019

Thanks for your Pull Request! 😄 This repo on GitHub is just a mirror of our real git repositories though, and can't really handle PRs. 😦 Hopefully you can redo the PR, and direct it to the git.postgresql.org repos? We have a developer guide, if that helps: https://wiki.postgresql.org/wiki/So,_you_want_to_be_a_developer%3F. If this was a PR for pgAdmin, please visit https://www.pgadmin.org/docs/pgadmin4/dev/submitting_patches.html.

@repo-lockdown repo-lockdown bot closed this Jun 17, 2019
@repo-lockdown repo-lockdown bot locked and limited conversation to collaborators Jun 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants