pgcat icon indicating copy to clipboard operation
pgcat copied to clipboard

PGcat detection from code

Open olivierACRI opened this issue 1 year ago • 1 comments

Is there a way to detect that we are connected to pgcat from the code (doing a special request that won't crash on a real database and will answer something different from pgcat)

olivierACRI avatar Apr 19 '24 08:04 olivierACRI

You could use the intercept plugin to intercept your own SQL command and return a value.

From the example config:

[plugins.intercept.queries.0]

query = "select current_database() as a, current_schemas(false) as b"
schema = [["a", "text"], ["b", "text"]]
result = [["${DATABASE}", "{public}"]]

[plugins.intercept.queries.1]

query = "select current_database(), current_schema(), current_user"
schema = [
  [
    "current_database",
    "text",
  ],
  [
    "current_schema",
    "text",
  ],
  [
    "current_user",
    "text",
  ],
]
result = [["${DATABASE}", "public", "${USER}"]]

tobyhede avatar May 05 '24 06:05 tobyhede