Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pgtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1992,12 +1992,15 @@ force_pgtt_namespace(void)
* schema
*/
bool at_end = false;
int len = strlen(old_search_path) - 11;
int len = strlen(old_search_path) - 10;
char *p = strstr(old_search_path, "pg_catalog");
if (p != NULL && strcmp(p, "pg_catalog") == 0)
{
if (len > 11)
old_search_path[len] = '\0';
/* remove redundant whitespaces */
while (len > 0 && isspace(old_search_path[len - 1]))
len--;
old_search_path[len] = '\0';

appendStringInfo(&search_path, "%s %s", old_search_path, pgtt_schema);
at_end = true;
}
Expand Down
40 changes: 40 additions & 0 deletions test/expected/13_searchpath.out
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,43 @@ SHOW search_path ;
public, pgtt_schema
(1 row)

-- Test only pg_catalog in search_path.
DROP EXTENSION pgtt;
\c - -
SHOW search_path;
search_path
-----------------
"$user", public
(1 row)

SET search_path TO pg_catalog;
SHOW search_path;
search_path
-------------
pg_catalog
(1 row)

CREATE EXTENSION pgtt;
SHOW search_path;
search_path
--------------------------
pgtt_schema, pg_catalog
(1 row)

-- Test the pg_catalog at end of search_path.
DROP EXTENSION pgtt;
\c - -
SET search_path TO "$user", public, pg_catalog;
SHOW search_path;
search_path
-----------------------------
"$user", public, pg_catalog
(1 row)

CREATE EXTENSION pgtt;
SHOW search_path;
search_path
------------------------------------------
"$user", public, pgtt_schema, pg_catalog
(1 row)

17 changes: 17 additions & 0 deletions test/sql/13_searchpath.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@ SET search_path TO pg_catalog;
SHOW search_path ;
SET search_path TO public;
SHOW search_path ;

-- Test only pg_catalog in search_path.
DROP EXTENSION pgtt;
\c - -
SHOW search_path;
SET search_path TO pg_catalog;
SHOW search_path;
CREATE EXTENSION pgtt;
SHOW search_path;

-- Test the pg_catalog at end of search_path.
DROP EXTENSION pgtt;
\c - -
SET search_path TO "$user", public, pg_catalog;
SHOW search_path;
CREATE EXTENSION pgtt;
SHOW search_path;