How can I enter multiple values into an aggregate function using just data I enter at the command line? Say, in Postgres, I run the following.
SELECT AVG(2);
I'll get the correct answer, but I can't find a way to enter multiple values, such as below, without getting an error.
SELECT AVG(1,NULL,2,3);
I've tried wrapping the numbers in various brackets but to no effect. What's the syntax I'm missing?
EDIT: Additionally, is there a way to include NULLs in the input?
AVG()is an aggregate that operates over multiple rows. So you need to convert your comma separated list to one row per value to be able to use an aggregate likeavg(). This could be done using e.g.string_to_tableIf you want to include a NULL value, you could add it to the list and convert it to null before casting it to a numeric value: