Display View Column Names in vsql

Moderator: NorbertKrupa

Post Reply
User avatar
heather
Newbie
Newbie
Posts: 22
Joined: Fri Dec 28, 2012 3:01 pm

Display View Column Names in vsql

Post by heather » Tue Sep 24, 2013 1:33 pm

Hi,

How can I display the the columns in a view in vsql? The \d and \dv commands don't show the columns :cry: I have to keep selecting just one row (limit 1) to check the column names.

Thanks

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Display View Column Names in vsql

Post by id10t » Tue Sep 24, 2013 2:09 pm

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;

User avatar
heather
Newbie
Newbie
Posts: 22
Joined: Fri Dec 28, 2012 3:01 pm

Re: Display View Column Names in vsql

Post by heather » Tue Sep 24, 2013 2:31 pm

Ok, thanks, sKwa. I was hoping there was a describe option like a describe table...

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Display View Column Names in vsql

Post by id10t » Tue Sep 24, 2013 3:54 pm

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

User avatar
heather
Newbie
Newbie
Posts: 22
Joined: Fri Dec 28, 2012 3:01 pm

Re: Display View Column Names in vsql

Post by heather » Tue Sep 24, 2013 4:05 pm

Thanks, sKwa! That's cool! I will use this solution :D :D :D

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Display View Column Names in vsql

Post by JimKnicely » Tue Sep 24, 2013 8:22 pm

#skwa: That is a really cool solution!
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

Post Reply

Return to “vSQL”