Regular Expression Replace of Primary Key
Nugget posted by Mark Fenoglio
November 8, 2009

For a lot of application that I create, I have a series of shell scripts that essentially help me rebuild the database contents from scratch. One component of that is SQL reports for various entities in the application, the delivery of which is simple INSERT INTO statements.

In some cases, I leave the primary key values alone, since they also represent foreign keys in other tables that have data. In most cases, however, I want the primary key to be populated using the defaults I've set in the PostgreSQL database.

I use regular expression global replace in TextMate to make this happen:

VALUES (\('[0-9]*'), 

is replaced with

VALUES (DEFAULT,