A Different Dialect

Entering the Far Archive

12 min

The signal that wasn't noise

The last expedition ended with a faint signal from a dead sector. For eight weeks, the station dismissed it as an echo. Today the receiver picked it up again — and this time, it came with a header.

The Far Archive is a massive columnar store containing records from Earth's last colony. This is neither a storefront nor an analytics warehouse: it holds years of the colony's LIFE, far too much to read row by row.

The archive has something no database in this course has had before: a meter. Every query draws power from a dying donor station, and the meter charges for every byte read. You can't simply “look at all the data” here — you'll have to learn to ask precise questions.

QUERY studies the header longer than usual and, for the first time in two courses, says:

I don't know this . We'll learn it together. But I understood one rule right away: this archive charges for every byte it reads.

A cadet enters the Far Archive for the first time: instead of shelves of rows, the hall is built from tall, glowing COLUMNS of data; a faint signal from a dead sector wakes three of them, a three-level address frame hangs nearby, and a robot cat watches the columns come alive.
The archive stores data by column rather than by row, and each table is identified by three names — both the query cost and the key difference from Postgres start there.

A table address: three names instead of one

In Postgres, you wrote FROM users, and the database looked for the table in the current schema. In BigQuery, a table's full address has three levels:

SELECT * FROM `project.dataset.table`
  • project — whose archive this is, and whose account pays for the query;
  • — a section of the archive, similar to a schema;
  • table — the table itself.

Backticks ` aren't decoration: without them, a name containing a hyphen or a dot can be split into separate parts. Make a habit of wrapping full table addresses in backticks from the start.

The course sandbox is already connected to the archive's dataset, so the cells below only need the short table name — as if you'd already run USE dataset. You'll need the full address once you start working with many tables across different sections.

The archive's first table is the colony resident registry, fa_users. Run it:

Table address: three names instead of onePostgresFROM userscurrent schemaBigQuery`arena.far.fa_users`projectdatasettablebackticks are needed because a project id may contain a hyphen
A table's full address: project, dataset, and table name instead of a single current schema
SELECT *
FROM fa_users
ORDER BY user_id
LIMIT 5;

Why this archive is columnar

In a row-oriented database such as Postgres or MySQL, data is stored in rows. Reading one row is cheap, but reading one column across a billion rows is expensive because the disk still has to pull in the full rows.

BigQuery stores data in columns: the status values for all orders sit together, separately from items and total. This changes two familiar query habits:

  1. A query pays only for the columns it READS. SELECT name FROM fa_users touches one column; SELECT * touches them all.
  2. “Fetch one row by id” is a poor fit here: there are no indexes, and the archive is built for questions that scan “all rows at once.”

The station's meter follows the same rule and drains energy for the columns read. We'll get the full price list in the next lesson; for now, remember that SELECT * in BigQuery can mean a bigger bill.

SELECT * EXCEPT — hide columns without listing the rest

In Postgres, if you wanted “every column except one,” you had to list all the others by hand. With a 40-column table, that's 39 lines of pain.

BigQuery handles this with one construct:

SELECT * EXCEPT(tags) FROM fa_users

“Every column except tags.” You can also pass a list: EXCEPT(tags, joined_at). Try it:

EXCEPT hides, REPLACE substitutesSELECT * EXCEPT(tags)idnamecityplantagsSELECT * REPLACE(UPPER(city) AS city)idnameCITYplantagsthe other columns need not be listed
Hide a column or replace it with an expression without listing every other column
SELECT * EXCEPT(tags, joined_at)
FROM fa_users
ORDER BY user_id;

SELECT * REPLACE — replace a column on the fly

The second construct in the same family keeps every column but replaces one with an expression, leaving the others untouched:

SELECT * REPLACE(UPPER(status) AS status) FROM fa_orders

The name after AS must match an existing column name because REPLACE replaces that column rather than adding a new one. Run it and look at the status column: REPLACE changed its values, while every other column stayed in place.

SELECT * REPLACE(UPPER(status) AS status)
FROM fa_orders
ORDER BY order_id
LIMIT 5;

An array in a cell: the table is no longer flat

Go back to the first result: the tags column didn't contain strings — it contained lists of strings. In Postgres, you'd probably put them in a separate user_tags table and connect that table with a . BigQuery allows a column to have the type ARRAY<STRING>, so the entire list can live inside one cell.

Use ARRAY_LENGTH to measure the length of the list:

SELECT name, ARRAY_LENGTH(tags) AS tag_count FROM fa_users

Which colony resident has the most tags — and who has none at all?

SELECT name, colony, ARRAY_LENGTH(tags) AS tag_count
FROM fa_users
ORDER BY tag_count DESC, name;
Check yourself
In Postgres, you wrote SELECT id, name, city, phone, email, plan, created_at, updated_at, source, score, manager, note FROM leads — every column except raw_payload. How would you write the same thing in BigQuery in one line?
Check yourself
What will SELECT ARRAY_LENGTH(tags) FROM fa_users return for a resident with no tags, when the cell contains an empty array []?

Cliffhanger: how to turn an array into rows

A list inside a cell is convenient until you want to count by element: how many residents have the tag “engineer”? To answer that, you need to expand the array into rows. In Postgres, you'd use unnest() in a lateral join; in BigQuery, the standard pattern is CROSS JOIN UNNEST, and it has a catch that can silently drop rows.

We'll cover that in the “Arrays and Structures” chapter. Before the archive lets you go deeper, though, it wants you to understand its meter — the next lesson explains what exactly you're paying for.

Practice today's material with these exercises:

Practice: solve the tasks
Solved 0 of 2 · any 1 is enough to pass
Key takeaways
  • a full table address is `project.dataset.table` in backticks; the sandbox is already inside the
  • BigQuery stores data by column: you pay for the columns read, and SELECT * is the most expensive way to ask
  • SELECT * EXCEPT(a, b) means every column except the named ones; SELECT * REPLACE(expr AS col) replaces a column on the fly
  • a column can contain an array: ARRAY<STRING> lives inside a cell, ARRAY_LENGTH measures its length, and an empty array ≠

Next up — the archive meter: which bytes you're charged for, and why LIMIT won't save you.