Skip to content

Instantly share code, notes, and snippets.

@solidsnack
Created December 29, 2013 20:04
Show Gist options
  • Select an option

  • Save solidsnack/8174206 to your computer and use it in GitHub Desktop.

Select an option

Save solidsnack/8174206 to your computer and use it in GitHub Desktop.
# This Python/Scala like syntax with type annotations
# would be easier for people to write.
def join_convention(a: Table, b: Table):
col: Column = b.columns[a.table_name]
[ * for * in join(a, b) on a(id) = b(col) ]
# This is more a sketch than anything. The handling of functions,
# table column lookups, actual properties of tables and columns,
# and "computed" tables and columns are all important in the syntax.
==== becomes ====
-- Note that 'regclass' is a Postgres type that is a pointer to a table.
CREATE FUNCTION join_convention(a regclass, b regclass)
RETURNS SETOF record AS $$ BEGIN
RETURN QUERY EXECUTE
'SELECT * FROM '||a||' JOIN '||b||' ON ('||a||'.id = '||b||'.'||a||')';
END $$ LANGUAGE plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment