Skip to content

Instantly share code, notes, and snippets.

@Ch4s3
Created September 21, 2020 23:19
Show Gist options
  • Save Ch4s3/8100fa09ab947e1def24685130a3aa5c to your computer and use it in GitHub Desktop.
Save Ch4s3/8100fa09ab947e1def24685130a3aa5c to your computer and use it in GitHub Desktop.

Revisions

  1. Ch4s3 created this gist Sep 21, 2020.
    6 changes: 6 additions & 0 deletions select_2_explain.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    from(c in City, select: c) # returns the schema as a struct
    from(c in City, select: {c.name, c.population}) # returns Tuple of {name, population}
    from(c in City, select: [c.name, c.county]) # returns List of [name, county]
    from(c in City, select: %{n: c.name, answer: 42}) # returns Map with keys :n, and :answer
    from(c in City, select: %{c | alternative_name: c.name}) # returns the schema as a Struct with :alternative_name added
    from(c in City, select: %Data{name: c.name}) # returns the selected name in %Data{}