0

Is it possible to use functions or expressions to create an alias name?

For example, is there a way to use concat like this?

SELECT
  id."myamazingrecords"
FROM
  records AS CONCAT("my", "amazing", "records")

I'm looking for a general way to programmatically (via SQL) rename columns in the output of my query.

1 Answer 1

2

No, an alias has to be a literal.

You can either construct the alias in client code before you send the query to the server, or you use a PL/pgSQL function that executes a dynamic query like

EXECUTE format('SELECT id."myamazingrecords" FROM records AS %I',
                CONCAT('my', 'amazing', 'records'));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.