Michael Sheaver
Michael Sheaver

Reputation: 2119

PostgreSQL: Meaning of 'AS f(x)' Clause in SELECT Statement

In a presentation on Window functions made by EDB (https://youtu.be/XO1WnmJs9RI), they start out with what they call the simplest form of a window function as this:

SELECT *
FROM generate_series(1, 10) AS f(x);

What is the meaning of the AS f(x) clause at the end of this statement? I searched the documentation under both the SELECT command and the window function, and cannot find any explanation for this syntax. I know that the AS portion allows us to rename the column, but I am clueless on the f(x) part.

Upvotes: 1

Views: 402

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270361

This is simply a table alias that defines the result of generate_series():

  • The table reference is f.
  • The column reference is x.

The as is optional (and I leave it out of table aliases).

So, you could write the select as:

select f.x

This is handy when you want to use the value for other purposes, such as calculations and joins.

Upvotes: 4

Related Questions