Postgresql – Convert query for count and updated date

aggregatepostgresqlquerysnowflake

I currently run the below query in Snowflake for some of my reconciliations and have never worked in PostgreSQL, which we just adopted.

Select count(1), min (LAST_UPDATED_DATE), max(LAST_UPDATED_DATE)
from "SOURCE"."SCHEMA"."TABLE"

I'm looking to do the same thing in PostgreSQL. It's one that we can run against a table that will give us the last updated date and a count when checking that movements completed.

I know Postgres can be time heavy on counts and some of these tables are massive. That aside I'm not sure how to rewrite this to begin with.

Best Answer

Starting point, mostly unchanged:

SELECT count(*), min(last_updated_date), max(last_updated_date)
FROM   schema.table;
  • Be aware of (not) case sensitive behavior of identifiers in Postgres. If in doubt use legal, unquoted, lower-case names exclusively. See:

  • A table can optionally be schema-qualified (schema.table), but not database-qualified. A name like from "SOURCE"."SCHEMA"."TABLE" would raise:

ERROR:  cross-database references are not implemented: "SOURCE.SCHEMA.TABLE"