There is an BSD-licensed Lua binding to libpq which gives you more or less all features found in the libpq C library in Lua:
LuaPgSQL