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

Conditionally inject dependencies of functions #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

feikesteenbergen
Copy link

For some functions, it is possible that the functions it depends
upon are not explicitly present, e.g. for the following aggregate
function, the dependency is upon pg_catalog.array_cat, so should not even be
made explicit.

CREATE AGGREGATE array_agg_mult(anyarray) (
    SFUNC = array_cat,
    STYPE = anyarray,
    INITCOND = '{}'
);

We got the following error when trying to dbtoyaml this database

KeyError: (u'public', 'array_cat', u'anyarray, anyarray')

@feikesteenbergen
Copy link
Author

Arguably, this is still wrong, as the following definition is perfectly valid, yet cause dbtoyaml to raise an error:

SET search_path = a, pg_catalog;

--
-- Name: _group_concat(text, text); Type: FUNCTION; Schema: a; Owner: postgres
--

CREATE FUNCTION _group_concat(text, text) RETURNS text
    LANGUAGE sql IMMUTABLE
    AS $_$
SELECT CASE
  WHEN $2 IS NULL THEN $1
  WHEN $1 IS NULL THEN $2
  ELSE $1 || ', ' || $2
END
$_$;


ALTER FUNCTION a._group_concat(text, text) OWNER TO postgres;

SET search_path = b, pg_catalog;

--
-- Name: group_concat(text); Type: AGGREGATE; Schema: b; Owner: postgres
--

CREATE AGGREGATE group_concat(text) (
    SFUNC = a._group_concat,
    STYPE = text
);


ALTER AGGREGATE b.group_concat(text) OWNER TO postgres;

The error raised is:

  File "/Users/feike/Library/Python/2.7/lib/python/site-packages/Pyrseas-0.8.0-py2.7.egg/pyrseas/dbobject/__init__.py", line 567, in unqualify
    assert sch == self.schema
AssertionError

For some functions, it is possible that the functions it depends
upon are not explicitly present, e.g. for the following aggregate
function:

CREATE AGGREGATE array_agg_mult(anyarray) (
    SFUNC = array_cat,
    STYPE = anyarray,
    INITCOND = '{}'
);

We got the following error when trying to dbtoyaml this database

KeyError: (u'public', 'array_cat', u'anyarray, anyarray'), but
the dependency is upon pg_catalog.array_cat, so should not even be
made explicit.
@jmafc
Copy link
Member

jmafc commented May 17, 2018

Yes, this is essentially the same problem raised by #175. Unless we read all of pg_catalog, we can't properly determine how to deal with it. Hence the need for #185--the trick is to fetch the pg_catalog information (and use it internally), but do not dump the pg_catalog schema.
I'm going to hold off on merging this for a while.

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

Successfully merging this pull request may close these issues.

2 participants