Page 1 of 1
Display View Column Names in vsql
Posted: Tue Sep 24, 2013 1:33 pm
by heather
Hi,
How can I display the the columns in a view in vsql? The \d and \dv commands don't show the columns
I have to keep selecting just one row (limit 1) to check the column names.
Thanks
Re: Display View Column Names in vsql
Posted: Tue Sep 24, 2013 2:09 pm
by id10t
Hi!
Code: Select all
daniel=> select export_objects('','view_name');
Code: Select all
daniel=> select ordinal_position, column_name, data_type from view_columns where table_name = 'view_name' order by ordinal_position;
Re: Display View Column Names in vsql
Posted: Tue Sep 24, 2013 2:31 pm
by heather
Ok, thanks, sKwa. I was hoping there was a describe option like a describe table...
Re: Display View Column Names in vsql
Posted: Tue Sep 24, 2013 3:54 pm
by id10t
Hi!
If you are using vsql you always can set an alias:
Code: Select all
daniel=> \set show_view 'select ordinal_position, column_name, data_type from view_columns where table_name = '
daniel=> :show_view 'my_view';
ordinal_position | column_name | data_type
------------------+-------------+-------------
1 | id | int
2 | name | varchar(80)
3 | salary | int
4 | dept | int
(4 rows)
write it in '.vsqlrc' file to set it permanent
Re: Display View Column Names in vsql
Posted: Tue Sep 24, 2013 4:05 pm
by heather
Re: Display View Column Names in vsql
Posted: Tue Sep 24, 2013 8:22 pm
by JimKnicely
#skwa: That is a really cool solution!