# Query fail in Postgres Extension

**URL:** <https://community.dynatrace.com/t/query-fail-in-postgres-extension/54177>\
**Category:** Extensions\
**Tags:** databases, extensions\
**Created:** [November 24, 2025, 9:00am UTC](https://community.dynatrace.com/t/query-fail-in-postgres-extension/54177 "2025-11-24T09:00:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArneV](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@ArneV](https://community.dynatrace.com/u/ArneV)\
**Post date:** [November 24, 2025, 9:00am UTC](https://community.dynatrace.com/t/query-fail-in-postgres-extension/54177/1 "2025-11-24T09:00:20Z")

</div>

I have written an extension to try to monitor the content of a table in a postgres DB.

However it looks as if im a bit stupid..

When i try to run my SQL directly against the DB it works.

However when i put it into my build extension, it fails.

Query has failed: ERROR: function date\_subtract(date, unknown) does not exist  
Hint: No function matches the given name and argument types. You might need to add explicit type casts.

sqlPostgres:&nbsp; - group: Latest data&nbsp; &nbsp; featureSet: “Latest”&nbsp; &nbsp; interval:&nbsp; &nbsp; &nbsp; minutes: 1 #Executed every minute&nbsp; &nbsp; ingest: metrics&nbsp; &nbsp; query: \>&nbsp; &nbsp; &nbsp; Select&nbsp; &nbsp; &nbsp; &nbsp; \*&nbsp; &nbsp; &nbsp; From&nbsp; &nbsp; &nbsp; &nbsp; business\_alert&nbsp; &nbsp; &nbsp; where&nbsp; &nbsp; &nbsp; &nbsp; Created \>= date\_subtract (CURRENT\_DATE, ‘5 minute’)&nbsp; &nbsp; &nbsp; order by&nbsp; &nbsp; &nbsp; &nbsp; Type &nbsp;desc&nbsp; &nbsp; &nbsp; &nbsp; fetch first 1 rows only&nbsp; &nbsp; metrics:&nbsp; &nbsp; &nbsp; - key: mytest.sql.extension.value&nbsp; &nbsp; &nbsp; &nbsp; value: col:Type&nbsp; &nbsp; dimensions:&nbsp; &nbsp; &nbsp; - key: stat\_name&nbsp; &nbsp; &nbsp; &nbsp; value: const:latest

Why would it complain over&nbsp;date\_subtract?

---

<div class="post-metadata">

**Author:** ![AntonPineiro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antonpineiro/32/49_2.png) [@AntonPineiro](https://community.dynatrace.com/u/AntonPineiro)\
**Post date:** [November 24, 2025, 10:16am UTC](https://community.dynatrace.com/t/query-fail-in-postgres-extension/54177/2 "2025-11-24T10:16:21Z")

</div>

Hi,

Maybe you can try [this extension path](https://www.dynatrace.com/hub/detail/custom-database-extension/?query=queries&filter=all).

Best regards

---

<div class="post-metadata">

**Author:** ![PacoPorro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pacoporro/32/36087_2.png) [@PacoPorro](https://community.dynatrace.com/u/PacoPorro)\
**Post date:** [November 24, 2025, 10:43am UTC](https://community.dynatrace.com/t/query-fail-in-postgres-extension/54177/3 "2025-11-24T10:43:34Z")

</div>

try with  
WHERE created \>= NOW() - INTERVAL ‘5 minutes’

---

<div class="post-metadata">

**Author:** ![ArneV](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@ArneV](https://community.dynatrace.com/u/ArneV)\
**Post date:** [November 24, 2025, 11:51am UTC](https://community.dynatrace.com/t/query-fail-in-postgres-extension/54177/4 "2025-11-24T11:51:26Z")

</div>

I will try this, however my frustration is that, i do have a SQL that can execute directly against my postgress.

But it does not work with the extension build following DT sugestion.

I will give the “Now” way a shoot.

---

<div class="post-metadata">

**Author:** ![ArneV](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@ArneV](https://community.dynatrace.com/u/ArneV)\
**Post date:** [November 24, 2025, 11:52am UTC](https://community.dynatrace.com/t/query-fail-in-postgres-extension/54177/5 "2025-11-24T11:52:14Z")

</div>

This dosent really explain why the SQL is not working.

---

<div class="post-metadata">

**Author:** ![david\_lopes](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/david_lopes/32/27273_2.png) [@david\_lopes](https://community.dynatrace.com/u/david_lopes)\
**Post date:** [November 24, 2025, 10:42pm UTC](https://community.dynatrace.com/t/query-fail-in-postgres-extension/54177/6 "2025-11-24T22:42:42Z")

</div>

You query is NOT valid PostgreSQL dialect, I don’t know how you are making this work with some other tool, there is no such thing as “date\_subtract” in postgres.

It could be that someone created a custom function, but that is not going to be available from the extension, you will need to provide the schema name where that function is defined.

You can check if that is the case by running

```css
SELECT
    n.nspname as schema,
    p.proname as function_name,
    pg_get_function_arguments(p.oid) as arguments,
    pg_get_functiondef(p.oid) as definition
  FROM
    pg_proc p
    JOIN pg_namespace n ON p.pronamespace = n.oid
  WHERE
    p.proname = 'date_subtract';

```

Then you would modify the extension to use schema\_name.date\_subtract(…)

---

<div class="post-metadata">

**Author:** ![ArneV](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@ArneV](https://community.dynatrace.com/u/ArneV)\
**Post date:** [December 2, 2025, 6:18am UTC](https://community.dynatrace.com/t/query-fail-in-postgres-extension/54177/7 "2025-12-02T06:18:43Z")

</div>

Well thats strange, im using DBeaver and execute it against a local DB. So somthing must be right.

It’s also described by&nbsp;[PostgreSQL: Documentation: 18: 9.9.&nbsp;Date/Time Functions and Operators](https://www.postgresql.org/docs/current/functions-datetime.html)

---

<div class="post-metadata">

**Author:** ![ArneV](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@ArneV](https://community.dynatrace.com/u/ArneV)\
**Post date:** [December 2, 2025, 10:54am UTC](https://community.dynatrace.com/t/query-fail-in-postgres-extension/54177/8 "2025-12-02T10:54:39Z")

</div>

I did try it with your SQL sugestion. And it does not complain anymore.

However i tried to add a dimension to it.

dimensions:&nbsp; &nbsp; &nbsp; - key: stat\_name&nbsp; &nbsp; &nbsp; &nbsp; value: const:latestAnd i started to get the error:Error in YAML configuration. Failed to parse extension YAML: Dimension value must be prefixed with one of: [“col:”, “const:”, “var:”] but the value is Timestamp, line: N/A, column: N/A; Datasource has exited and will be starting shortlyHowever as you can see no Timestamp in it.It’s as if some “old” code wasen’t removed from what i was working with.Kind of driving me nuts..Will try to delete the extension.

---

<div class="post-metadata">

**Author:** ![ArneV](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@ArneV](https://community.dynatrace.com/u/ArneV)\
**Post date:** [December 4, 2025, 9:20am UTC](https://community.dynatrace.com/t/query-fail-in-postgres-extension/54177/9 "2025-12-04T09:20:06Z")

</div>

Finaly had time to test it, and yes this actualy does work.
