Select
SELECT
is a commonly used statement that allows you to rename attributes and create new ones based on expressions.
The syntax for SELECT
is:
`SELECT <code> AS attribute, ...`
Where <code>
could be an attribute or an expression.
SELECT *
The most important use case for
SELECT
is
SELECT *;
.The
*
represents all attributes that are not otherwise referenced in theSELECT
statement. It is useful to start almost all of your scripts withSELECT *, ...
. Note that in Formula, we automatically include aSELECT *
and you do not have to remember to write it yourself.
Using SELECT
to Rename Attributes
SELECT
to Rename AttributesThis is the simplest form of SELECT
:
SELECT *, attribute1 AS attribute2;
.
The table that results from this statement has the values that were previously in attribute1
in attribute2
. You can rename as many attributes as you want. For example:
SELECT *, attribute1 AS attribute2, attribute3 AS attribute4;
Viewing Attributes in Your Unified Dataset
To view an attribute in your table, you must choose “Create attribute” on the Schema Mapping or Unified Dataset page. If you do not do this, then the attribute will not appear in your unified dataset. You can still reference the attribute in your scripts, but it will not appear in preview or in export.
Generating Attributes Based on Expressions with SELECT
SELECT
You can write expressions with SELECT
to manipulate the values in attributes. For example, you could multiply the Product_Price
by a conversion factor to change currencies:
SELECT *, (Product_Price * conversion_factor) AS Product_Price;
You could also choose to have both currencies in your table in separate columns.
SELECT *, (Product_US_Price * conversion_factor) AS Product_EU_Price;
Do Not Forget to Include SELECT *
Note that if you did not write
SELECT *
at the beginning of these statements, the table from these transformations would only have the attributesProduct_EU_Price
, orProduct_EU_Price
andProduct_US_Price
, respectively.
Updated over 4 years ago