INSERT..RETURNING in postgres.js
So as you all know, we've been working on postgres support for the up-and-coming node.js environment, and we just got a great new example of Postgres' functionality that we're proud to say we support - specifically, the query format INSERT..RETURNING. For those unfamiliar with INSERT..RETURNING, this type of query allows us to do just what it says - return a value, or set of values, after an INSERT statement. This is really useful when dealing with sequences, as your application layer can be notified of new primary keys, or other values that might be interesting. Here's how it works:
-- SQL for setup.
CREATE TABLE returning_test (id serial not null, val text);

// postgres.js code

var sys = require("sys");
var pg = require("./lib/postgres-pure");

var db = new pg.connect("pgsql://test:12345@localhost:5432/returning_test");
db.prepare("INSERT INTO returning_test (val) VALUES (?) RETURNING id", 
    function (sth) {
        sth.execute("text value", function(rs) {
            if (rs === undefined) {
                console.log("No data.");
            }
            else {
                console.log(sys.inspect(rs));
            }
        });
});

// And our output:
$ node demo.js
[ { id: 4 } ]

// Subsequent runs, as expected:  
[ { id: 5 } ]
[ { id: 6 } ]
[ { id: 7 } ]
[ { id: 8 } ]
Easily done, and using the exact same prepared syntax that postgres.js uses for SELECT statements - exactly as you'd expect a query returning data to operate. Postgres also does complex RETURNING, which would be:

var db = new pg.connect("pgsql://test:12345@localhost:5432/returning_test");
db.prepare("INSERT INTO returning_test (val) VALUES (?) RETURNING id, val", 
    function (sth) {
        sth.execute("text value", function(rs) {
            if (rs === undefined) {
                console.log("No data.");
            }
            else {
                console.log(sys.inspect(rs));
            }
        });
});

[ { id: 9, val: 'text value' } ]

Postgres.js is MIT-licensed and available from github. Check out the reasonably stable version, or help out with development on the development branch. Patches are always appreciated!