Database |> Language |> 

Variables

Contents

Definition

Variables allow you to break off values into defined readable aliases. This can be done using either the pipe operator wih the <| pointing towards the name of the variable and the tokens before the | at the end making up the definition.

name_of_variable <| value |

Or, using the ASSIGN keyword as a prefix operator instead.

ASSIGN name_of_variable value

Example

We can use variables for the URL being requested FROM as well as the selectors being SELECTed or GROUPed by. For example we can take the following LSD SQL to retrieve post titles and links from the front page of Hacker News:

FROM https://news.ycombinator.com
|> GROUP BY span.titleline
|> SELECT a, a@href

With variables to have the resulting code be more readable and easily editable.

hn <| https://news.ycombinator.com |
repeating_container <| span.titleline |
post_title <| a |
post_link <| a@href |

FROM hn
|> GROUP BY repeating_container
|> SELECT post_title, post_link

So, if we were interested in tweaking the LSD SQL to retrieve posts from Ask HN instead of the front page, we’d simply edit the value for hn.

hn <| https://news.ycombinator.com/ask |
repeating_container <| span.titleline |
post_title <| a |
post_link <| a@href |

FROM hn
|> GROUP BY repeating_container
|> SELECT post_title, post_link

Related: