Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix[PostgreSQLConnector]: Rand() not supported in postgresql #570

Merged
merged 1 commit into from
Sep 18, 2023
Merged
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
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()")
gventuri marked this conversation as resolved.
Show resolved Hide resolved

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