简体   繁体   English

如何在 Vertica 中搜索 column_names?

[英]How to search column_names in Vertica?

Anyone know of a handy function to search through column_names in Vertica?任何人都知道一个方便的 function 来搜索 Vertica 中的 column_names 吗? From the documentation, it seems like \d only queries table_names.从文档看来,\d 似乎只查询表名。 I'm looking for something like MySQL's information_schema.columns, but can't find any information about a similar table of meta-data.我正在寻找类似 MySQL 的 information_schema.columns 之类的东西,但找不到有关类似元数据表的任何信息。

Thanks!谢谢!

In 5.1 if you have enough permissions you can do在 5.1 中如果你有足够的权限你可以做

SELECT * FROM v_catalog.columns;

to access columns's info, for some things you'll need to join with访问列的信息,对于一些你需要加入的东西

v_catalog.tables

The answer may differ depending on the version of Vertica you are using.答案可能因您使用的 Vertica 版本而异。

In the latest version, 5.1, there is a COLUMNS system table.在最新版本 5.1 中,有一个 COLUMNS 系统表。 Just from looking at the online documentation here seems to be the most useful columns with their types:仅从这里的在线文档来看,似乎是最有用的列及其类型:

TABLE_SCHEMA VARCHAR
TABLE_NAME VARCHAR
DATA_TYPE VARCHAR

That should give you what you need.那应该给你你需要的。 If your version doesn't have the system table, let me know what version you're running and I'll see what we can do.如果您的版本没有系统表,请告诉我您正在运行的版本,我会看看我们能做些什么。

Wrap this python script in a shell function and you'll be able to see all tables that contain any two columns: import argparse将这个 python 脚本包装在 shell function 中,您将能够看到包含任意两列的所有表:import argparse

parser = argparse.ArgumentParser(description='Find Vertica attributes in tables')
parser.add_argument('names', metavar='N', type=str, nargs='+', help='attribute names')
args = parser.parse_args()


def vert_attributes(*names):
    first_name = names[0].lower()
    first = "select root.table_name, root.column_name from v_catalog.columns root "
    last = " where root.column_name like '%s' " % first_name
    names = names[1:]
    if len(names) >= 1:
        return first + " ".join([" inner join (select table_name from v_catalog.columns where column_name like '%s') q%s on root.table_name = q%s.table_name " % (name.lower(), index, index) for index,name in enumerate(names)]) + last
    else:
        return first + last

print nz_attributes(*tuple(args.names))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM