Skip to content

Instantly share code, notes, and snippets.

@aodin
Created December 16, 2016 18:11
Show Gist options
  • Save aodin/e39cb4514a7bcc488390000672235d79 to your computer and use it in GitHub Desktop.
Save aodin/e39cb4514a7bcc488390000672235d79 to your computer and use it in GitHub Desktop.
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