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
Ejzy postgre sql export #152
Conversation
Not yet sure where to put this - here is code for exporting procedures: SELECT 'CREATE FUNCTION ' || routine_name || '() RETURNS ' || data_type || ' AS $_$' ||
routine_definition || '$_$ LANGUAGE ' || external_language
FROM information_schema.routines
WHERE specific_schema = 'public'
AND routine_name = 'delete_address'; |
@helix84 This SQL looks nice&easy but does not work for functions with parameters because of missing parameters definition of the function. It's not really easy to get them and create SQL. I'll try to move forward with this, but the first step is to get pull-request merged. |
Since 4.2.1 there is fatal error in exporting selected lines in PostgreSQL as the create_sql function is called (&missing). Merging this pull-request resolves this error as it adds "create_sql" function to pgsql driver. |
Yes, that was my reason why I looked into this, too. |
I made some preparations to export functions in pgsql, had to move some code to drivers. The function's parameters issue not resolved, bud the structure of code should be obvious. https://github.com/ejzy/adminer/commit/6b173a7cd1989674b23d95273db18ce8abd5d059 |
Perhaps this will help us with getting the arguments (I didn't dig into it yet): SELECT proretset, prosrc, probin,
pg_catalog.pg_get_function_arguments(oid) AS funcargs,
pg_catalog.pg_get_function_identity_arguments(oid) AS funciargs,
pg_catalog.pg_get_function_result(oid) AS funcresult,
proiswindow, provolatile, proisstrict, prosecdef,
proleakproof, proconfig, procost, prorows,
(SELECT lanname FROM pg_catalog.pg_language WHERE oid = prolang) AS lanname
FROM pg_catalog.pg_proc
WHERE proname = 'FUNCNAME'; |
Here's my first attempt based on pg_dump's dumpFunc(). Needs testing. SELECT 'CREATE FUNCTION ' || proname || '(' || funcargs || ') RETURNS ' || funcresult || E'\n' ||
'AS $$ ' || prosrc || ' $$ LANGUAGE ' || lanname || a.window || a.volatile || a.strict || a.secdef || leakproof || cost || rows
FROM (
SELECT nspname, proname, proretset, prosrc, probin,
pg_catalog.pg_get_function_arguments(b.oid) AS funcargs,
pg_catalog.pg_get_function_result(b.oid) AS funcresult,
CASE proiswindow
WHEN 't' THEN ' WINDOW'
ELSE ''
END AS window,
CASE provolatile
WHEN 's' THEN ' STATIC'
WHEN 'i' THEN ' IMMUTABLE'
ELSE ''
END AS volatile,
CASE proisstrict
WHEN 't' THEN ' STRICT'
ELSE ''
END AS strict,
CASE prosecdef
WHEN 't' THEN ' SECURITY DEFINER'
ELSE ''
END AS secdef,
CASE proleakproof
WHEN 't' THEN ' LEAKPROOF'
ELSE ''
END AS leakproof,
CASE
WHEN (((SELECT lanname FROM pg_catalog.pg_language WHERE oid = prolang) IN ('internal', 'c')) AND procost != 0)
THEN ' COST ' || procost
ELSE ''
END AS cost,
CASE
WHEN (proretset = 't' AND prorows != 0 AND prorows != 1000) THEN ' ROWS ' || prorows
ELSE ''
END AS rows,
proconfig, -- TODO proconfig
(SELECT lanname FROM pg_catalog.pg_language WHERE oid = prolang) AS lanname
FROM pg_catalog.pg_proc b, pg_namespace
WHERE pg_namespace.oid=pronamespace
AND proname = 'FUNCNAME'
AND nspname = 'public'
) AS a |
Looks good. Should be changed to the current_schema() to list functions of selected schema, but it's just cosmetic. We should consider version of postgresql, because 'leakproof' is supported 9.2+, which is not so old version and could break compatibility for some users ( i would keep compatibility for major version). There are some other issues regarding 8.4- which is older major version and could be abandoned IMHO. |
This is the function name and schema, to be parametrized. I created this according to the latest supported pg version in pg_dump 9.4, but I agree we should make the newer functions optional depending on detected driver version. I'd also support 8.4, I still have one such server to test with. Which problems do you see in 8.4? Seems to work for me (when I remove leakproof) and dumpFunc() also treats <8.4, 9.2) the same. |
Sure, we can just place
to list all functions of given schema. If you can test it on 8.4, let's keep it without leakproof for now and it should work on 8.4+, which should be enough. |
As we mentioned the bug in exporting select results, #133 should solve it as well, without merging PostgreSQL export functionality into master. |
…lice, komentare, definice triggeru (bez definice jejich funkci)
- definition added after creating all tables in given database
9fa82ad
to
d750d73
Compare
Has any progress been made on merging this into Adminer? This functionality would be really useful for us as we're struggling along with phpPgAdmin (which hasn't been updated in ~3 years) |
How is this not merged yet? 😞 |
I gave up, there is no progress. @vrana stated in other issue he is currently busy and only minor changes are merged. |
Merged the first commit. There were some conflicts and I fixed some style issues. Please test it. About the second commit: resolve "needs more inspection", avoid a global variables, indent using tabs and create a separate pull request for it. |
Unfortunately, trying 4.2.6-dev, I get an error on Postgres in the list of tables screen. The tables are still shown correctly.
(Despite what the error says, I don't have a table called "c".) |
Please try it at the current HEAD. I've merged a bad pull request introducing the |
Thanks, now it passed my smoke test. The error message is gone and a simple table export works. |
A rebase of #137 on current master.
👍 I tested it and it enables most of the Export functionality.