0

Given a messy postgres query (e.g. with lots of subqueries) is there a way to figure out what columns will be returned by the query without running the query itself?

If I understand correctly, Sequel's Dataset#columns method (Documentation) calls the query with a LIMIT 1 attached. That's fine for a simple query, but if subqueries are involved it seems that this approach still results in computing those subqueries.

(One approach might be to add a LIMIT 1 to every subquery, but I'm not exactly sure how to go about doing that.)

I'm using Postgres 9.2 with Sequel.

Thanks! (I know this question isn't as precisely posed as might be desirable -- please let me know what more information I can provide that might be helpful.)

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
brahn
  • 12,096
  • 11
  • 39
  • 49

1 Answers1

1

You can do this with explain and add the option VERBOSE. Have a look here

http://www.postgresql.org/docs/9.1/static/sql-explain.html
idipous
  • 2,868
  • 3
  • 30
  • 45