A data pipeline configuration system expects exactly two output columns — one named from containing the source node ID of 100, and one named to containing the destination node ID of 200. Both from and to are SQL reserved words, so they must be wrapped in double quotes when used as column names.
Write a query that returns those two values in a single row with the required column names.
Output:
- A single row with two columns named exactly
fromandto.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
100 AS "from",
200 AS "to" The shape
The double quotes around "from" and "to" are what let two SQL reserved words sit in the SELECT list as column names instead of being parsed as syntax.
Clause by clause
SELECT 100 AS "from"is the first expression: the source node ID, labeled with the column name the pipeline expects. The double quotes tell PostgreSQL the tokenfromis an identifier, not the start of aFROMclause.200 AS "to"is the second expression: the destination node ID, labeled the same way.tois reserved too, so it needs the same treatment.- The comma between the two expressions is what makes them sit in the same row. Two labeled integer literals, two quoted aliases, one row with the exact column headers the pipeline configuration system requires.
Why this and not AS from
SELECT 100 AS from fails immediately. The parser sees the keyword from and tries to start a FROM clause, then runs out of input — there's no table name after it. The error is a syntax error, not an alias error, because PostgreSQL never got to treat from as a name; it saw the keyword first.
Double quotes change how the parser reads the token. Anything inside double quotes is an identifier. "from" is no longer the keyword from; it's the name from. The same rule covers "select", "where", "order", and every other reserved word.
The trap
The column header you get back is the bare word from without quotes. The quotes are syntax for the query, not part of the name. That can read like the query somehow stripped them; it didn't, the quotes were always just instructions to the parser. If the same query later references the column, the reference also needs the double quotes — "from", not from. Whenever an alias matches a reserved word, the quoting has to be there everywhere the name appears.
You practiced quoting an alias to use a SQL reserved word as a column name. Reserved words like from, to, select, where are otherwise illegal as bare identifiers — the recurring fix is AS "reserved_word", which forces PostgreSQL to treat the token as an identifier rather than syntax.