Skip to content

Commit

Permalink
fix: rand() not supported in postgresql (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArslanSaleem authored Sep 18, 2023
1 parent 390c597 commit 4e0aadb
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pandasai/connectors/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,25 @@ def __init__(self, config: ConnectorConfig):
config["password"] = os.getenv("POSTGRESQL_PASSWORD")

super().__init__(config)

@cache
def head(self):
"""
Return the head of the data source that the connector is connected to.
This information is passed to the LLM to provide the schema of the data source.
Returns:
DataFrame: The head of the data source.
"""

if self.logger:
self.logger.log(
f"Getting head of {self._config.table} "
f"using dialect {self._config.dialect}"
)

# Run a SQL query to get all the columns names and 5 random rows
query = self._build_query(limit=5, order="RANDOM()")

# Return the head of the data source
return pd.read_sql(query, self._connection)

0 comments on commit 4e0aadb

Please sign in to comment.