Is it possible to capture the output of postgres blocks?

How hard would it be to capture the output of postgres blocks? My current workflow is to use a psql block to design my query, then I use a normal script block to invoke ‘psql -t’ with some json_agg and jq to get my response into a script variable.

I’ll share an example once I’m back at my desk.

Just wondering if it’s on the road map, or possible at all, really

EDIT: here is what I currently do in a script block:

nix shell nixpkgs#postgresql -c psql -t {{var.CONNECTION_STRING | trim}}/mydb -c \
  "SELECT json_agg(row_to_json(t)) FROM
    (SELECT foo FROM table WHERE bar = '{{var.XXX}}') t" \
  | jq .[0].foo

It’s not currently possible to capture the output of database blocks, but it is something we have on our roadmap. We’d like all blocks to have an “output” with data that’s accessible to other blocks. We’re laying the groundwork for this now with our new execution engine, but don’t currently have a good estimate for a timeframe.

1 Like

Thanks ! In the meantime I have a workaround so I’m good :wink: Keep up the amazing work