Skip to content

Instantly share code, notes, and snippets.

@aodin aodin/onion.sql
Created Dec 16, 2016

Embed
What would you like to do?
Onion SQL Schema
CREATE TABLE things_versioned (
id integer not null,
name varchar not null,
version timestamp with time zone default now(),
PRIMARY KEY (id, version)
)
CREATE VIEW things AS
SELECT
DISTINCT ON (id)
id AS "id",
name AS "name",
version AS "updated_at"
FROM things_versioned
ORDER BY id ASC, version DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.