Repository: duckdb/duckdb (language: python)

Issue:
Max expression depth limit exceeded on "SHOW TABLES"
### What happens?

```
$ duckdb /tmp/test.duckdb
v1.1.1 af39bd0dcf
Enter ".help" for usage hints.
D SET search_path = pg_catalog;
D SHOW TABLES;
Binder Error: Max expression depth limit of 1000 exceeded. Use "SET max_expression_depth TO x" to increase the maximum expression depth.
```

However this works:

```
$ duckdb /tmp/test.duckdb
v1.1.1 af39bd0dcf
Enter ".help" for usage hints.
D SHOW TABLES;
D SET search_path = pg_catalog;
D SHOW TABLES;
Binder Error: Max expression depth limit of 1000 exceeded. Use "SET max_expression_depth TO x" to increase the maximum expression depth.
```



### To Reproduce

```sql
SET search_path = pg_catalog;
```
```console
SHOW TABLES;
Binder Error: Max expression depth limit of 1000 exceeded. Use "SET max_expression_depth TO x" to increase the maximum expression depth.
```

### OS:

Ubuntu x86_64

### DuckDB Version:

v1.1.1 af39bd0dcf

### DuckDB Client:

Command line tool (duckdb)

### Hardware:

_No response_

### Full Name:

Prashanth Ellina

### Affiliation:

None

### What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a stable release

### Did you include all relevant data sets for reproducing the issue?

Not applicable - the reproduction does not require a data set

### Did you include all code required to reproduce the issue?

- [X] Yes, I have

### Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

- [X] Yes, I have


Discussion / hints:

Fix patch:
diff --git a/src/catalog/default/default_functions.cpp b/src/catalog/default/default_functions.cpp
index b4f7deca4be0..f7f4634b9932 100644
--- a/src/catalog/default/default_functions.cpp
+++ b/src/catalog/default/default_functions.cpp
@@ -12,7 +12,7 @@ namespace duckdb {
 static const DefaultMacro internal_macros[] = {
 	{DEFAULT_SCHEMA, "current_role", {nullptr}, {{nullptr, nullptr}}, "'duckdb'"},                       // user name of current execution context
 	{DEFAULT_SCHEMA, "current_user", {nullptr}, {{nullptr, nullptr}}, "'duckdb'"},                       // user name of current execution context
-	{DEFAULT_SCHEMA, "current_catalog", {nullptr}, {{nullptr, nullptr}}, "current_database()"},          // name of current database (called "catalog" in the SQL standard)
+	{DEFAULT_SCHEMA, "current_catalog", {nullptr}, {{nullptr, nullptr}}, "main.current_database()"},          // name of current database (called "catalog" in the SQL standard)
 	{DEFAULT_SCHEMA, "user", {nullptr}, {{nullptr, nullptr}}, "current_user"},                           // equivalent to current_user
 	{DEFAULT_SCHEMA, "session_user", {nullptr}, {{nullptr, nullptr}}, "'duckdb'"},                       // session user name
 	{"pg_catalog", "inet_client_addr", {nullptr}, {{nullptr, nullptr}}, "NULL"},                       // address of the remote connection
@@ -27,10 +27,10 @@ static const DefaultMacro internal_macros[] = {
 
 	{"pg_catalog", "pg_typeof", {"expression", nullptr}, {{nullptr, nullptr}}, "lower(typeof(expression))"},  // get the data type of any value
 
-	{"pg_catalog", "current_database", {nullptr}, {{nullptr, nullptr}}, "current_database()"},  	    // name of current database (called "catalog" in the SQL standard)
-	{"pg_catalog", "current_query", {nullptr}, {{nullptr, nullptr}}, "current_query()"},  	        // the currently executing query (NULL if not inside a plpgsql function)
-	{"pg_catalog", "current_schema", {nullptr}, {{nullptr, nullptr}}, "current_schema()"},  	        // name of current schema
-	{"pg_catalog", "current_schemas", {"include_implicit"}, {{nullptr, nullptr}}, "current_schemas(include_implicit)"},  	// names of schemas in search path
+	{"pg_catalog", "current_database", {nullptr}, {{nullptr, nullptr}}, "main.current_database()"},  	    // name of current database (called "catalog" in the SQL standard)
+	{"pg_catalog", "current_query", {nullptr}, {{nullptr, nullptr}}, "main.current_query()"},  	        // the currently executing query (NULL if not inside a plpgsql function)
+	{"pg_catalog", "current_schema", {nullptr}, {{nullptr, nullptr}}, "main.current_schema()"},  	        // name of current schema
+	{"pg_catalog", "current_schemas", {"include_implicit"}, {{nullptr, nullptr}}, "main.current_schemas(include_implicit)"},  	// names of schemas in search path
 
 	// privilege functions
 	{"pg_catalog", "has_any_column_privilege", {"table", "privilege", nullptr}, {{nullptr, nullptr}}, "true"},  //boolean  //does current user have privilege for any column of table


Test patch:
diff --git a/test/sql/catalog/test_set_search_path.test b/test/sql/catalog/test_set_search_path.test
index 66a9ce7d3f8b..17ea585d5690 100644
--- a/test/sql/catalog/test_set_search_path.test
+++ b/test/sql/catalog/test_set_search_path.test
@@ -234,3 +234,28 @@ SELECT i FROM test2_table;
 statement ok con2
 SELECT i FROM test2_table;
 
+# Same system functions in pg and duckdb
+
+statement ok
+SET search_path = pg_catalog;
+
+statement ok
+SELECT current_database();
+
+statement ok
+SELECT current_catalog();
+
+query I
+SELECT current_schema();
+----
+pg_catalog
+
+query I
+SELECT current_schemas(true);
+----
+[main, pg_catalog, main, main, pg_catalog]
+
+query I
+SELECT current_query();
+----
+SELECT current_query();