summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmjith Ramanujam <amjith.r@gmail.com>2021-05-07 12:52:45 -0700
committerGitHub <noreply@github.com>2021-05-07 12:52:45 -0700
commitd8532df22e1f309c8a05a452d752bd30f4869bbe (patch)
tree2235b0a531bdf4122431310a252a31139e85d9a1
parent0ada5a6c6aa1ca1d1e028f00691862629f521308 (diff)
parent898f8255e051ee6a64099723f21f31980ecdd380 (diff)
Merge pull request #1266 from dbcli/search_path_functions
Include functions from search_path in completion.
-rw-r--r--.pre-commit-config.yaml2
-rw-r--r--changelog.rst1
-rw-r--r--pgcli/main.py3
-rw-r--r--pgcli/packages/pgliterals/pgliterals.json2
-rw-r--r--pgcli/pgcompleter.py8
-rw-r--r--tests/test_smart_completion_multiple_schemata.py30
-rw-r--r--tests/utils.py2
7 files changed, 41 insertions, 7 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index b970ac5e..9e27ab8e 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
- rev: stable
+ rev: 21.5b0
hooks:
- id: black
language_version: python3.7
diff --git a/changelog.rst b/changelog.rst
index 4fd6fb28..21941499 100644
--- a/changelog.rst
+++ b/changelog.rst
@@ -7,6 +7,7 @@ Features:
* Consider `update` queries destructive and issue a warning. Change
`destructive_warning` setting to `all|moderate|off`, vs `true|false`. (#1239)
* Skip initial comment in .pg_session even if it doesn't start with '#'
+* Include functions from schemas in search_path. (`Amjith Ramanujam`_)
Bug fixes:
----------
diff --git a/pgcli/main.py b/pgcli/main.py
index ecf041bb..2202c1a7 100644
--- a/pgcli/main.py
+++ b/pgcli/main.py
@@ -1248,7 +1248,8 @@ def cli(
else:
print("Config file is now located at", config_full_path)
print(
- "Please move the existing config file ~/.pgclirc to", config_full_path,
+ "Please move the existing config file ~/.pgclirc to",
+ config_full_path,
)
if list_dsn:
try:
diff --git a/pgcli/packages/pgliterals/pgliterals.json b/pgcli/packages/pgliterals/pgliterals.json
index 5c292e6d..df00817a 100644
--- a/pgcli/packages/pgliterals/pgliterals.json
+++ b/pgcli/packages/pgliterals/pgliterals.json
@@ -327,8 +327,6 @@
"FIRST_VALUE",
"FLOOR",
"FORMAT",
- "GENERATE_SERIES",
- "GENERATE_SUBSCRIPTS",
"GET_BIT",
"GET_BYTE",
"HEIGHT",
diff --git a/pgcli/pgcompleter.py b/pgcli/pgcompleter.py
index 79be274e..227e25c6 100644
--- a/pgcli/pgcompleter.py
+++ b/pgcli/pgcompleter.py
@@ -140,7 +140,7 @@ class PGCompleter(Completer):
return "'{}'".format(self.unescape_name(name))
def unescape_name(self, name):
- """ Unquote a string."""
+ """Unquote a string."""
if name and name[0] == '"' and name[-1] == '"':
name = name[1:-1]
@@ -703,7 +703,11 @@ class PGCompleter(Completer):
not f.is_aggregate
and not f.is_window
and not f.is_extension
- and (f.is_public or f.schema_name == suggestion.schema)
+ and (
+ f.is_public
+ or f.schema_name in self.search_path
+ or f.schema_name == suggestion.schema
+ )
)
else:
diff --git a/tests/test_smart_completion_multiple_schemata.py b/tests/test_smart_completion_multiple_schemata.py
index 74768d39..5c9c9af4 100644
--- a/tests/test_smart_completion_multiple_schemata.py
+++ b/tests/test_smart_completion_multiple_schemata.py
@@ -350,6 +350,36 @@ def test_schema_qualified_function_name(completer):
)
+@parametrize("completer", completers(filtr=True, casing=False, aliasing=False))
+def test_schema_qualified_function_name_after_from(completer):
+ text = "SELECT * FROM custom.set_r"
+ result = get_result(completer, text)
+ assert completions_to_set(result) == completions_to_set(
+ [
+ function("set_returning_func()", -len("func")),
+ ]
+ )
+
+
+@parametrize("completer", completers(filtr=True, casing=False, aliasing=False))
+def test_unqualified_function_name_not_returned(completer):
+ text = "SELECT * FROM set_r"
+ result = get_result(completer, text)
+ assert completions_to_set(result) == completions_to_set([])
+
+
+@parametrize("completer", completers(filtr=True, casing=False, aliasing=False))
+def test_unqualified_function_name_in_search_path(completer):
+ completer.search_path = ["public", "custom"]
+ text = "SELECT * FROM set_r"
+ result = get_result(completer, text)
+ assert completions_to_set(result) == completions_to_set(
+ [
+ function("set_returning_func()", -len("func")),
+ ]
+ )
+
+
@parametrize("completer", completers(filtr=True, casing=False))
@parametrize(
"text",
diff --git a/tests/utils.py b/tests/utils.py
index fcd725e3..460ea469 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -73,7 +73,7 @@ def drop_tables(conn):
def run(
executor, sql, join=False, expanded=False, pgspecial=None, exception_formatter=None
):
- " Return string output for the sql to be run "
+ "Return string output for the sql to be run"
results = executor.run(sql, pgspecial, exception_formatter)
formatted = []