Would it be possible to create a view from a table showing all its fields in the original order but one without specifically naming all of them? Also, would it be possible to do the same but moving that field to the last column of the view?
Asked
Active
Viewed 36 times
0
-
1No, not with static SQL, there is no syntax for that. You could use dynamic SQL based on the data dictionary, but might be more hassle than just typing the names. Why don't you want to name them? – Alex Poole Mar 10 '21 at 20:51
-
Because I'll be changing/adding the original fields' names and would want the view to adapt dynamically. – Javi Torre Mar 10 '21 at 20:53
-
It can't adapt dynamically, you would need to recreate it; in which case having a procedure to do that on demand (again, from the data dictionary) might work. (I was looking afor [this](https://stackoverflow.com/q/9133120/266304) but it's not really a duplicate now; but still might be helpful.) – Alex Poole Mar 10 '21 at 21:00
-
I've also tried the select listagg thing but the columns are order alphabetically. Is there a way to avoid this? – Javi Torre Mar 10 '21 at 21:19
-
Why does it matter what orders the columns are in ? – Koen Lostrie Mar 10 '21 at 21:41
-
The view is later exported to csv and that's the order in which the users will see it. – Javi Torre Mar 10 '21 at 21:42
-
Typically, the order of columns and views shouldn't matter. You determine in your query what columns you want to see and it what order. – Koen Lostrie Mar 10 '21 at 21:46
-
"Because I'll be changing/adding the original fields' names" If this happens on a regular basis, then you have a seriously flawed data model. Also, in relational databases, the various data elements of a table are called 'columns', not 'fields'. – EdStevens Mar 10 '21 at 21:52