Skip to content
Advertisement

How do I return a table from a function with a bespoke column name?

This function works:

But when I try to add some text to the column name:

This just fails as a syntax error on $1.
Or:

select * from a('some prefix') doesn’t work.
Is there some other syntax that does the job?

Advertisement

Answer

That’s simply not possible. SQL does not allow dynamic column names.

You must assign a column alias with the call. Like:

Or in a column definition list directly attached to the function:

Or, while dealing with a single output column, even just:

See:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement