L
L
leremin2017-01-26 11:04:42
PostgreSQL
leremin, 2017-01-26 11:04:42

How to rename column name in SELECT to function value?

In general, the task is to display 7 columns so that the name of the n-th column has a name like the date of the n-th day of a certain week. But, in short, how to execute, for example, such a query:
SELECT date(now()) AS date(now());
Subd - PostgreSQL

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Shelemetiev, 2017-01-26
@leremin

You can first generate the request text, for example:

select 
'SELECT '
|| '"' || string_agg(d, '", "') || '"'
from (
  select 
    to_char((now()::date - (extract(dow from now()::date))::integer + 1 + i::integer),'dd.mm.yyyy') d 
  from 
    generate_series(0, 6) i
) q0

Then execute the resulting text.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question