Posting explains from tools (and not web browsers)

Some time ago (well, a month ago) someone called zam6ak reached to me and asked about extraction of delete_key from plans posted using tool, and not website.

Specifically they were doing something like:

curl --silent --include \
    --request "POST" "https://explain.depesz.com/" \
    --data-urlencode "title=sample" \
    --data-urlencode "plan@sample-plan.txt" \
    --data-urlencode "query@sample-query.sql" \
    --data-urlencode "is_public=0"

Which worked, and redirected them to page that displays explain. But it wasn't trivial to extract url to delete the explain once it's no longer needed.

Took me a while to get it, but now, one can:

=$ curl --silent \
    --request "POST" "https://explain.depesz.com/" \
    --header "Accept: application/json" \
    --data-urlencode "title=sample" \
    --data-urlencode "plan@sample-plan.txt" \
    --data-urlencode "query@sample-query.sql" \
    --data-urlencode "is_public=0"

And you will get JSON like this one (not pretty printed, though):

{
  "delete_key": "eQl699oPB63ZtYYmwLPRiJp33Bi3TnmK7S8ho35uKrq6FAvwIv",
  "id": "2Q38",
  "urls": {
    "delete": "https://explain.depesz.com/d/2Q38/eQl699oPB63ZtYYmwLPRiJp33Bi3TnmK7S8ho35uKrq6FAvwIv",
    "show": "https://explain.depesz.com/s/2Q38"
  }
}

Hope someone will find it helpful 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.