Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "s.a" mean in this generate_series() query

I'm trying this for returning business days, but I don´t understand s.a and s(a) in this query:

SELECT dia 
FROM (
    SELECT ('2012-08-01'::date + s.a * '1 day'::interval) AS dia
    FROM generate_series(0, '2012-08-31'::date - '2012-08-01'::date, 1) AS s(a)
) foo
WHERE EXTRACT(DOW FROM dia) BETWEEN 1 AND 5
EXCEPT
SELECT feriado_data FROM teste.feriado;

Could someone explain it for me?

like image 820
Jacomini Avatar asked Feb 20 '23 02:02

Jacomini


1 Answers

s in s(a) is a table alias given to the set returned by generate_series and the a in s(a) is the alias given to its only column.

Refer to table expression docs and scroll to "Another form of table aliasing gives temporary names to the columns of the table" for full details.

like image 87
Clodoaldo Neto Avatar answered Feb 28 '23 09:02

Clodoaldo Neto