internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: mindsdb/mindsdb

Issue:
Add option to list tables in PostgreSQL integration :bookmark_tabs: 
When users create a connection to the database it will be useful to show them tips with a list of tables. To be able to do this we need a new method `get_tables_list` implemented in the PostgreSQL integration class.

## Steps :male_detective: :female_detective: 

- Frok MindsDB repo
- Add new implementation in https://github.com/mindsdb/mindsdb/blob/stable/mindsdb/integrations/postgres/postgres.py#L37
- Make a PR to staging branch

## Additional rewards :1st_place_medal: 

Each code PR brings  :three:  point for entry into the draw for a :computer:  Deep Learning Laptop powered by the NVIDIA RTX 3080 Max-Q GPU or other swag :shirt: :bear: .  For more info check out https://mindsdb.com/hacktoberfest/


Discussion:
Hello, can you please assign me to this issue? I can work on this.
This is cool may I work on this too? 
@ZoranPandovski can you please clarify which tables need to be fetched and what info regarding each table is required.

Resolving patch:
diff --git a/mindsdb/integrations/postgres/postgres.py b/mindsdb/integrations/postgres/postgres.py
--- a/mindsdb/integrations/postgres/postgres.py
+++ b/mindsdb/integrations/postgres/postgres.py
@@ -199,3 +199,13 @@ def get_row_count(self, query):
             FROM ({query}) as query;"""
         result = self._query(q)
         return result[0]['count']
+    
+    def get_tables_list(self):
+        q = f""" SELECT table_schema, table_name
+                      FROM information_schema.tables
+                      WHERE table_schema != 'pg_catalog'
+                      AND table_schema != 'information_schema'
+                      ORDER BY table_schema, table_name"""
+        tables_list = self._query(q)
+        tables= [f"{table['table_schema']}.{table['table_name']}" for table in tables_list]
+        return tables
\ No newline at end of file


Test patch:
Repository: mindsdb/mindsdb

Issue:
Add @@transaction_isolation MySQL variable



Discussion:

Resolving patch:
diff --git a/mindsdb/api/mysql/mysql_proxy/libs/constants/mysql.py b/mindsdb/api/mysql/mysql_proxy/libs/constants/mysql.py
--- a/mindsdb/api/mysql/mysql_proxy/libs/constants/mysql.py
+++ b/mindsdb/api/mysql/mysql_proxy/libs/constants/mysql.py
@@ -980,7 +980,10 @@ class WARN(object):
     '@@version': ('0.1', TYPES.MYSQL_TYPE_VAR_STRING, CHARSET_NUMBERS['utf8_general_ci']),
 
     '@@collation_connection': ('utf8_general_ci', TYPES.MYSQL_TYPE_VAR_STRING, CHARSET_NUMBERS['utf8_general_ci']),
-    '@@performance_schema': (1, TYPES.MYSQL_TYPE_LONGLONG, CHARSET_NUMBERS['binary'])
+    '@@performance_schema': (1, TYPES.MYSQL_TYPE_LONGLONG, CHARSET_NUMBERS['binary']),
+
+    '@@GLOBAL.transaction_isolation': ('REPEATABLE-READ', TYPES.MYSQL_TYPE_VAR_STRING, CHARSET_NUMBERS['utf8_general_ci']),
+    '@@transaction_isolation': ('REPEATABLE-READ', TYPES.MYSQL_TYPE_VAR_STRING, CHARSET_NUMBERS['utf8_general_ci']),
 }
 
 class SESSION_TRACK(object):


Test patch:
Repository: mindsdb/mindsdb

Issue:
Add option to list tables in MySQL integration :bookmark_tabs: 
When users create a connection to the MySQL database it will be useful to show them tips with a list of tables. To be able to do this we need a new method `get_tables_list` implemented in the MySQL integration class.

## Steps :male_detective: :female_detective: 

- Frok MindsDB repo
- Add new implementation in https://github.com/mindsdb/mindsdb/blob/stable/mindsdb/integrations/mysql/mysql.py#L51
- Make a PR to staging branch

## Additional rewards :1st_place_medal: 

Each code PR brings  :three:  point for entry into the draw for a :computer:  Deep Learning Laptop powered by the NVIDIA RTX 3080 Max-Q GPU or other swag :shirt: :bear: .  For more info check out https://mindsdb.com/hacktoberfest/


Discussion:
@ZoranPandovski Can I take a look ?

Resolving patch:
diff --git a/mindsdb/integrations/mysql/mysql.py b/mindsdb/integrations/mysql/mysql.py
--- a/mindsdb/integrations/mysql/mysql.py
+++ b/mindsdb/integrations/mysql/mysql.py
@@ -197,3 +197,10 @@ def get_row_count(self, query):
             FROM ({query}) as query;"""
         result = self._query(q)
         return result[0]['count']
+    
+    def get_tables_list(self):
+        q= f"""
+            SHOW TABLES;
+            """
+        result = self._query(q)
+        return result


Test patch:
Repository: mindsdb/mindsdb

Issue:
Add new method to return the columns for MySQL datasources :electric_plug: :1234: 
When MindsDB creates a new MySQL datasource we get information for columns by fetching all datasources. The problem here is that if datasource is big it takes a lot of time. We need a new get_columns method to return the columns name per datasource. The PR should include this method inside the MySQL class .

## Steps :male_detective: :female_detective: 

- Implement in https://github.com/mindsdb/mindsdb/blob/stable/mindsdb/integrations/mysql/mysql.py#L51
- Push to staging branch

## Additional rewards :1st_place_medal: 

Each code PR brings  :three:  point for entry into the draw for a :computer:  Deep Learning Laptop powered by the NVIDIA RTX 3080 Max-Q GPU or other swag :shirt: :bear: .  For more info check out https://mindsdb.com/hacktoberfest/
 




Discussion:

Resolving patch:
diff --git a/mindsdb/integrations/mysql/mysql.py b/mindsdb/integrations/mysql/mysql.py
--- a/mindsdb/integrations/mysql/mysql.py
+++ b/mindsdb/integrations/mysql/mysql.py
@@ -197,10 +197,19 @@ def get_row_count(self, query):
             FROM ({query}) as query;"""
         result = self._query(q)
         return result[0]['count']
+
+    def get_columns(self):
+        q = f"""SELECT COLUMN_NAME ,TABLE_NAME
+                    FROM INFORMATION_SCHEMA.COLUMNS 
+                    WHERE TABLE_SCHEMA = database()
+                    ORDER BY COLUMN_NAME, TABLE_NAME;"""
+        columns_list = self._query(q)
+        columns = [f"{columns[0]}.{columns[1]}" for columns in columns_list]
+        return columns
     
     def get_tables_list(self):
         q= f"""
             SHOW TABLES;
             """
         result = self._query(q)
-        return result
+        return result
\ No newline at end of file


Test patch:
Repository: mindsdb/mindsdb

Issue:
Add new method to return the columns for PostgreSQL datasources :electric_plug: :1234: 
When MindsDB creates a new PostgreSQL datasource we get information for columns by fetching all datasources. The problem here is that if datasource is big it takes a lot of time. We need a new get_columns method to return the columns name per datasource. The PR should include this method inside the PostgreSQL class .

## Steps :male_detective: :female_detective: 

- Implement in https://github.com/mindsdb/mindsdb/blob/staging/mindsdb/integrations/postgres/postgres.py#L37
- Push to staging branch

## Additional rewards :1st_place_medal: 

Each code PR brings  :three:  point for entry into the draw for a :computer:  Deep Learning Laptop powered by the NVIDIA RTX 3080 Max-Q GPU or other swag :shirt: :bear: .  For more info check out https://mindsdb.com/hacktoberfest/
 




Discussion:

Resolving patch:
diff --git a/mindsdb/integrations/postgres/postgres.py b/mindsdb/integrations/postgres/postgres.py
--- a/mindsdb/integrations/postgres/postgres.py
+++ b/mindsdb/integrations/postgres/postgres.py
@@ -208,4 +208,13 @@ def get_tables_list(self):
                       ORDER BY table_schema, table_name"""
         tables_list = self._query(q)
         tables= [f"{table['table_schema']}.{table['table_name']}" for table in tables_list]
-        return tables
\ No newline at end of file
+        return tables
+
+    def get_columns(self):
+        q = f"""SELECT column_name, table_name
+		FROM information_schema.columns
+		WHERE table_schema NOT IN ('information_schema', 'pg_catalog')
+		ORDER BY column_name, table_name;"""
+        columns_list = self._query(q)
+        columns = [f"{columns[0]}.{columns[1]}" for columns in columns_list]
+        return columns
\ No newline at end of file


Test patch:
Repository: mindsdb/mindsdb

Issue:
Add option to list tables in ClickHouse integration :bookmark_tabs: 
When users create a connection to the ClickHouse database it will be useful to show them tips with a list of tables. To be able to do this we need a new method `get_tables_list` implemented in the ClickHouse integration class.

## Steps :male_detective: :female_detective: 

- Frok MindsDB repo
- Add new implementation in https://github.com/mindsdb/mindsdb/blob/staging/mindsdb/integrations/clickhouse/clickhouse.py#L25
- Make a PR to staging branch

## Additional rewards :1st_place_medal: 

Each code PR brings  :three:  point for entry into the draw for a :computer:  Deep Learning Laptop powered by the NVIDIA RTX 3080 Max-Q GPU or other swag :shirt: :bear: .  For more info check out https://mindsdb.com/hacktoberfest/


Discussion:

Resolving patch:
diff --git a/mindsdb/integrations/clickhouse/clickhouse.py b/mindsdb/integrations/clickhouse/clickhouse.py
--- a/mindsdb/integrations/clickhouse/clickhouse.py
+++ b/mindsdb/integrations/clickhouse/clickhouse.py
@@ -151,3 +151,13 @@ def unregister_predictor(self, name):
             drop table if exists {self.mindsdb_database}.{self._escape_table_name(name)};
         """
         self._query(q)
+
+    def get_tables_list(self):
+        q = f"""SELECT database, table
+                    FROM system.parts
+                    WHERE active and database NOT IN  ('system', 'mdb_system')
+                    GROUP BY database, table
+                    ORDER BY database, table;"""
+        tables_list = self._query(q)
+        tables= [f"{table[0]}.{table[1]}" for table in tables_list]
+        return tables
\ No newline at end of file


Test patch:
Repository: mindsdb/mindsdb

Issue:
Add new method to return the columns for ClickHouse datasources :electric_plug: :1234: 
When MindsDB creates a new ClickHouse datasource we get information for columns by fetching all datasources. The problem here is that if datasource is big it takes a lot of time. We need a new get_columns method to return the columns name per datasource. The PR should include this method inside the ClickHouse class.

## Steps :male_detective: :female_detective: 

- Implement in https://github.com/mindsdb/mindsdb/blob/staging/mindsdb/integrations/clickhouse/clickhouse.py#L25
- Push to staging branch

## Additional rewards :1st_place_medal: 

Each code PR brings  :three:  point for entry into the draw for a :computer:  Deep Learning Laptop powered by the NVIDIA RTX 3080 Max-Q GPU or other swag :shirt: :bear: .  For more info check out https://mindsdb.com/hacktoberfest/
 




Discussion:

Resolving patch:
diff --git a/mindsdb/integrations/clickhouse/clickhouse.py b/mindsdb/integrations/clickhouse/clickhouse.py
--- a/mindsdb/integrations/clickhouse/clickhouse.py
+++ b/mindsdb/integrations/clickhouse/clickhouse.py
@@ -160,4 +160,12 @@ def get_tables_list(self):
                     ORDER BY database, table;"""
         tables_list = self._query(q)
         tables= [f"{table[0]}.{table[1]}" for table in tables_list]
-        return tables
\ No newline at end of file
+        return tables
+
+    def get_columns(self,query):
+        q = f"SELECT * FROM ({query}) LIMIT 1 FORMAT JSON"
+        query_result = self._query(q).json()
+        columns_info = query_result['meta']
+        columns= [column['name'] for column in columns_info]
+        return columns
+


Test patch:
Repository: mindsdb/mindsdb

Issue:
Add new method to return the columns for PostgreSQL datasources :electric_plug: :1234: 
When MindsDB creates a new PostgreSQL datasource we get information for columns by fetching all datasources. The problem here is that if datasource is big it takes a lot of time. We need a new get_columns method to return the columns name per datasource. The PR should include this method inside the PostgreSQL class .

## Steps :male_detective: :female_detective: 

- Implement in https://github.com/mindsdb/mindsdb/blob/staging/mindsdb/integrations/postgres/postgres.py#L37
- Push to staging branch

## Additional rewards :1st_place_medal: 

Each code PR brings  :three:  point for entry into the draw for a :computer:  Deep Learning Laptop powered by the NVIDIA RTX 3080 Max-Q GPU or other swag :shirt: :bear: .  For more info check out https://mindsdb.com/hacktoberfest/
 




Discussion:

Resolving patch:
diff --git a/mindsdb/integrations/postgres/postgres.py b/mindsdb/integrations/postgres/postgres.py
--- a/mindsdb/integrations/postgres/postgres.py
+++ b/mindsdb/integrations/postgres/postgres.py
@@ -210,11 +210,11 @@ def get_tables_list(self):
         tables= [f"{table['table_schema']}.{table['table_name']}" for table in tables_list]
         return tables
 
-    def get_columns(self):
-        q = f"""SELECT column_name, table_name
-		FROM information_schema.columns
-		WHERE table_schema NOT IN ('information_schema', 'pg_catalog')
-		ORDER BY column_name, table_name;"""
-        columns_list = self._query(q)
-        columns = [f"{columns[0]}.{columns[1]}" for columns in columns_list]
-        return columns
\ No newline at end of file
+    def get_columns(self,query):
+        q = f"""SELECT * from ({query}) LIMIT 1;"""
+        query_response = self._query(q)
+        if len(query_response) > 0:
+            columns = list(query_response[0].keys())
+            return columns
+        else:
+            return []
\ No newline at end of file


Test patch:
Repository: mindsdb/mindsdb

Issue:
Add new method to return the columns for MySQL datasources :electric_plug: :1234: 
When MindsDB creates a new MySQL datasource we get information for columns by fetching all datasources. The problem here is that if datasource is big it takes a lot of time. We need a new get_columns method to return the columns name per datasource. The PR should include this method inside the MySQL class .

## Steps :male_detective: :female_detective: 

- Implement in https://github.com/mindsdb/mindsdb/blob/stable/mindsdb/integrations/mysql/mysql.py#L51
- Push to staging branch

## Additional rewards :1st_place_medal: 

Each code PR brings  :three:  point for entry into the draw for a :computer:  Deep Learning Laptop powered by the NVIDIA RTX 3080 Max-Q GPU or other swag :shirt: :bear: .  For more info check out https://mindsdb.com/hacktoberfest/
 




Discussion:

Resolving patch:
diff --git a/mindsdb/integrations/mysql/mysql.py b/mindsdb/integrations/mysql/mysql.py
--- a/mindsdb/integrations/mysql/mysql.py
+++ b/mindsdb/integrations/mysql/mysql.py
@@ -198,18 +198,18 @@ def get_row_count(self, query):
         result = self._query(q)
         return result[0]['count']
 
-    def get_columns(self):
-        q = f"""SELECT COLUMN_NAME ,TABLE_NAME
-                    FROM INFORMATION_SCHEMA.COLUMNS 
-                    WHERE TABLE_SCHEMA = database()
-                    ORDER BY COLUMN_NAME, TABLE_NAME;"""
-        columns_list = self._query(q)
-        columns = [f"{columns[0]}.{columns[1]}" for columns in columns_list]
-        return columns
+    def get_columns(self,query):
+        q = f"""SELECT * from ({query}) LIMIT 1;"""
+        query_response = self._query(q)
+        if len(query_response) > 0:
+            columns = list(query_response[0].keys())
+            return columns
+        else:
+            return []
     
     def get_tables_list(self):
         q= f"""
             SHOW TABLES;
             """
         result = self._query(q)
-        return result
\ No newline at end of file
+        return result


Test patch:
Repository: mindsdb/mindsdb

Issue:
Add column 'error' to virtual table 'predictors'
At this moment if any error happen, then user will see only 'error' in 'status' column in 'predictors' table. We can provide additional info from `model['data']['error']` field.


Discussion:
@StpMax  I believe I have resolved this issue.  Please let me know if i missed anything or need to make any changes. 

Completed as part of hacktoberfest
Hi @askalik 
We do not need add new field to db, we already can get 'error' value from model data. Idea is to add this column to virtual 'predictors' table, to be able get error value by query 'select error from mindsdb.predictors;'

Resolving patch:
diff --git a/mindsdb/api/mysql/mysql_proxy/datahub/datanodes/mindsdb_datanode.py b/mindsdb/api/mysql/mysql_proxy/datahub/datanodes/mindsdb_datanode.py
--- a/mindsdb/api/mysql/mysql_proxy/datahub/datanodes/mindsdb_datanode.py
+++ b/mindsdb/api/mysql/mysql_proxy/datahub/datanodes/mindsdb_datanode.py
@@ -103,7 +103,7 @@ def getTableColumns(self, table):
     def _select_predictors(self):
         models = self.model_interface.get_models()
         columns = ['name', 'status', 'accuracy', 'predict', 'update_status',
-                   'mindsdb_version', 'select_data_query', 'external_datasource',
+                   'mindsdb_version', 'error', 'select_data_query', 'external_datasource',
                    'training_options']
         return pd.DataFrame([[
             x['name'],
@@ -112,6 +112,7 @@ def _select_predictors(self):
             ', '.join(x['predict']) if isinstance(x['predict'], list) else x['predict'],
             x['update'],
             x['mindsdb_version'],
+            x['error'],
             '',
             '',  # TODO
             ''  # TODO ?
diff --git a/mindsdb/interfaces/model/model_controller.py b/mindsdb/interfaces/model/model_controller.py
--- a/mindsdb/interfaces/model/model_controller.py
+++ b/mindsdb/interfaces/model/model_controller.py
@@ -309,7 +309,7 @@ def get_models(self, company_id: int):
 
             for k in ['name', 'version', 'is_active', 'predict', 'status',
                       'current_phase', 'accuracy', 'data_source', 'update',
-                      'data_source_name', 'mindsdb_version']:
+                      'data_source_name', 'mindsdb_version', 'error']:
                 reduced_model_data[k] = model_data.get(k, None)
 
             for k in ['train_end_at', 'updated_at', 'created_at']:


Test patch:
Repository: mindsdb/mindsdb

Issue:
Error when importing MindsDB in a Jupyter notebook
**Your Environment**

* Python version: 3.6
* Operating system: Ubuntu
* Mindsdb version: 2.12.2

**Describe the bug**
Importing MindsDB from a Jupyter Notebook fails, apparently because the HTTP API triggers.

**To Reproduce**
1. Run a new Jupyter notebook
2. Execute a cell with `import mindsdb`

The following error should occur:
```usage: ipykernel_launcher.py [-h] [--api API] [--config CONFIG] [--verbose] [-v]
ipykernel_launcher.py: error: unrecognized arguments: -f /home/user/.local/share/jupyter/runtime/kernel.json

An exception has occurred, use %tb to see the full traceback.
SystemExit: 2

/env/lib/python3.6/site-packages/IPython/core/interactiveshell.py:3351: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
```

**Expected behavior**
MindsDB should import successfully.

**Additional note**
`import mindsdb_native` works fine.


Discussion:

Resolving patch:
diff --git a/mindsdb/utilities/functions.py b/mindsdb/utilities/functions.py
--- a/mindsdb/utilities/functions.py
+++ b/mindsdb/utilities/functions.py
@@ -39,13 +39,10 @@ def cast_row_types(row, field_types):
 
 def is_notebook():
     try:
-        shell = get_ipython().__class__.__name__
-        if shell == 'ZMQInteractiveShell':
-            return True   # Jupyter notebook or qtconsole
-        elif shell == 'TerminalInteractiveShell':
-            return False  # Terminal running IPython
+        if 'IPKernelApp' in get_ipython().config:
+            return True
         else:
-            return False  # Other type (?)
+            return False
     except NameError:
         return False      # Probably standard Python interpreter
 


Test patch:
Repository: mindsdb/mindsdb

Issue:
Error when integration name contains space 
If the user adds the space in the integration name we are not able to parse that for e.g `My SQL`

```sql
mysql> CREATE PREDICTOR home_rentals_model FROM `My SQL`(SELECT * from test_data.home_rentals)  PREDICT rental_price;
ERROR 1149 (HY000): Expected "PREDICT" (at char 45), (line:1, col:46)
mysql>
```


Discussion:
@ZoranPandovski Can you give me a hint? Which function get the integration name?
@ZoranPandovski I have found some clues, please let me try.

Resolving patch:
diff --git a/mindsdb/api/mysql/mysql_proxy/classes/sql_statement_parser.py b/mindsdb/api/mysql/mysql_proxy/classes/sql_statement_parser.py
--- a/mindsdb/api/mysql/mysql_proxy/classes/sql_statement_parser.py
+++ b/mindsdb/api/mysql/mysql_proxy/classes/sql_statement_parser.py
@@ -123,7 +123,7 @@ def clear_sql(sql: str) -> str:
         expr = (
             originalTextFor(QuotedString("'"))
             | originalTextFor(QuotedString('"'))
-            | originalTextFor(QuotedString('`'))
+            | originalTextFor(QuotedString('\`'))
             | (oracleSqlComment | mySqlComment).suppress()
         )
 
@@ -191,7 +191,7 @@ def get_keyword(sql):
     def is_quoted_str(text):
         if isinstance(text, str) is False:
             return False
-        for quote in ['"', "'", '`']:
+        for quote in ['"', "'", '\`']:
             if text.startswith(quote) and text.endswith(quote):
                 return True
         return False
@@ -210,7 +210,7 @@ def is_float_str(text):
 
     @staticmethod
     def unquote(text):
-        for quote in ['"', "'", '`']:
+        for quote in ['"', "'", '\`']:
             if text.startswith(quote) and text.endswith(quote):
                 return text[1:-1]
         return text
@@ -445,9 +445,9 @@ def parse_as_delete(self) -> dict:
         and_ = Literal("and")
 
         from_value = (
-            QuotedString('`')
+            QuotedString('\`')
             | originalTextFor(
-                Word(printables, excludeChars='.`')
+                Word(printables, excludeChars='.\`')
             )
         )
 
@@ -521,9 +521,9 @@ def parse_as_insert(self) -> dict:
         word = Word(alphas)
 
         from_value = (
-            QuotedString('`')
+            QuotedString('\`')
             | originalTextFor(
-                Word(printables, excludeChars='().`')
+                Word(printables, excludeChars='().\`')
             )
         )
 


Test patch:
Repository: mindsdb/mindsdb

Issue:
Connection to CocroachDB is not possible



Discussion:

Resolving patch:
diff --git a/mindsdb/integrations/postgres/postgres.py b/mindsdb/integrations/postgres/postgres.py
--- a/mindsdb/integrations/postgres/postgres.py
+++ b/mindsdb/integrations/postgres/postgres.py
@@ -15,12 +15,16 @@ def __init__(self, **kwargs):
         self.database = kwargs.get('database', 'postgres')
 
     def _get_connection(self):
+        additional_args = {}
+        if 'cockroachlabs.cloud' in self.host:
+            additional_args['ssl_context'] = True
         return pg8000.connect(
             database=self.database,
             user=self.user,
             password=self.password,
             host=self.host,
-            port=self.port
+            port=self.port,
+            **additional_args
         )
 
     def check_connection(self):


Test patch: