paste.depesz.com is back (for good?)

Some time ago I removed paste.depesz.com because of some problems with underlying formatting library.

Now, it's back. New code, new approach, hopefully usable site.

So, previously I was using pgFormatter library, which was using pretty smart regexps to format SQL. But this library was improved in a non-backward-compatible way, and I couldn't really work on paste.depesz.com (then) to fix the problem.

Now, I got some time, and figured I'll look for some other approach.

I found great library pg_query – it's a ruby gem that wraps some magical C code, that is extracted from PostgreSQL sources. Long story short – it doesn't do its work using regexps. It uses proper parsing, and output from parser is normal parse tree.

It even consists of a method to print back SQL query from parse tree. This is what I used in my approach to make it print the query in somewhat nice way. Well, at least to my eyes it's pretty 🙂

At the moment, my patch with beautification code has not yet been merged, but I hope it eventually will (possibly with some changes.

In any way – I got my own clone of the library, with my beautification-related code, and am using it now at paste.depesz.com to format your queries.

The thing is that previously if pretty printing failed – it could have printed the queries badly indented or something. Now, if it fails – it just doesn't print anything in the “prettyfied" part of paste/show.

For now – it's should be OK – you can always see the original version of the query, even if pretty-printing fails.

I will be checking periodically to see what kind of queries fail on pretty printing, and will do my best to fix these problems.

2 thoughts on “paste.depesz.com is back (for good?)”

Leave a Reply

Your email address will not be published.

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