databases [...] need an external application
Wrong. There are plenty in-process database systems (for example SQLite which, with a little care, can be made fully ACID compliant).
is there a SQL (PostgreSQL preferably) database which I can compile along with my project and then issue queries locally?
Well I started answering before you added that remark, but again SQLite comes to mind. If this particular DB doesn't fit you, you may want to search for either "embedded database" or "in-process database", there are tons of similar products -- either SQL or even NoSQL ones.
One good NoSQL, key-value DB would be Berkeley DB but I'm afraid the license has tightened since Oracle bought it so I'm not sure if it's still relevant nowadays (unless your app is fully open-source or you can buy a commercial license).