Skip to content

Commit

Permalink
Overwrite some inherited methods on PostgresTable
Browse files Browse the repository at this point in the history
Some postgres columns (e.g. if they have a capital letter) need to be
surrounded by double quotes
  • Loading branch information
austinweisgrau committed Oct 10, 2024
1 parent 8791160 commit 46cea73
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion parsons/databases/postgres/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from parsons.databases.alchemy import Alchemy
from parsons.databases.database_connector import DatabaseConnector
from parsons.etl.table import Table
from typing import Optional
import logging
import os

Expand Down Expand Up @@ -102,4 +103,35 @@ def table(self, table_name):
class PostgresTable(BaseTable):
# Postgres table object.

pass
def max_value(self, column: str):
"""Get the max value of this column from the table."""
return self.db.query(
f"""
SELECT "{column}"
FROM {self.table}
ORDER BY "{column}" DESC
LIMIT 1
"""
).first

def get_updated_rows(
self,
updated_at_column: str,
cutoff_value,
offset: int = 0,
chunk_size: Optional[int] = None,
) -> Table:
"""Get rows that have a greater updated_at_column value than the one provided."""
sql = f"""
SELECT *
FROM {self.table}
WHERE "{updated_at_column}" > %s
"""
if chunk_size:
sql += f" LIMIT {chunk_size}"

sql += f" OFFSET {offset}"

result = self.db.query(sql, parameters=[cutoff_value])

return result

0 comments on commit 46cea73

Please sign in to comment.