Ruby

http://s.erious.ly

Posts tagged "sql"

Using BETWEEN for SQL comparisons

Recently, Carlos, suggested that I should start sharing some basic SQL tips that help with performance and/or general usage. I recently came across some code that I didn’t like to read and/or write. For example, let’s take the following…


SELECT * FROM brochures WHERE published_at <= now() AND archived_at >= now()

Essentially, this is pulling back...

Dealing with ‘duplicate key violates unique constraint’ on the primary key

I recently had to work through a problem where inserts were failing due to duplicate primary keys. Here’s the error (edited for clarity): PGError: ERROR: duplicate key violates unique constraint "contracts_pkey": INSERT INTO "contr...