0

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.

3
  • 1
    Hi, and welcome to the forum! Please provide your version of PostgreSQL, also your table's DDL, the actual text of your query and the result of EXPLAIN (ANALYZE, BUFFERS) <your query>...
    – Vérace
    Commented Feb 1, 2021 at 22:33
  • Why do you beleive that you have to rewrite the query? Commented Feb 1, 2021 at 23:06
  • @Lennart: Well, he does. A bit, at least. Commented Feb 1, 2021 at 23:10

1 Answer 1

2

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.