I tried using Oracle's DESCRIBE TABLE... statement in CockroachDB and got a syntax error. What’s the equivalent command?
In CockroachDB, the SHOW COLUMNS statement returns information about the columns in a table, similar to the DESCRIBE statement in MySQL and the \d command in PostgreSQL:
SHOW COLUMNS FROM tablename;
You can also get some information by running SHOW INDEX or SHOW CREATE TABLE or by querying the information_schema database.
Related
I use dbms_metadata.get_ddl(...) to get object ddl but it is not generate ddl for column.
is there way to get column ddl oracle 12 version?
thanks
I think following query may usefull for you.
SELECT *
FROM ADMIN.DDL_HISTORY_LOG L
WHERE L.OBJECT_TYPE = 'TABLE'
AND L.DDL = 'ALTER'
AND L.OBJECT_NAME = 'TABLE_NAME' --just change table name here
AND UPPER(L.DDL_SQL) LIKE '%ALTER%TABLE%ADD%'
AND UPPER(L.DDL_SQL) NOT LIKE '%ADD%CONSTRAINT%'
this oracle dictionary is holding all historic DDL statements. so, If you specify your table name, you can get all DDL statements for this table in the past.
I wonder if there is a way to get the data location from hive using a one-liner. Something like
select d.location from ( describe formatted table_name partition ( .. ) ) as d;
My current solution is to get the full output and then parse it.
Unlike traditional RDBMS, Hive metadata is stored in a separate database. In most cases it is in MySQL or Postgres. The metastore database details can be found in hive-site.conf. If you have access to the metastore database, you can run SELECT on table TBLS to get the details about the tables and COLUMNS_V2 to get the details about columns etc..
If you do not have access to the metastore, the only option is to describe each table to get the details. If you have a lot of databases and tables, you could write a shell script to get the list of tables using "show tables" and loop around the tables.
Two methods if you do not have access to the metadata.
Parse DESCRIBE TABLE in the shell like in this answer: https://stackoverflow.com/a/43804621/2700344
Also Hive has a virtual column INPUT__FILE__NAME.
select INPUT__FILE__NAME from table
will output locations URLs for each file.
You can split URL by '/', get element you need, aggregate, etc
How can I find out which tables I have in CockroachDB? I tried looking for my schema and couldn't find that, so I'm not sure how to find out which tables I've already created or what their columns are.
First, you'll need to find your databases (which are CockroachDB's equivalent to PostgreSQL's schemas) using either:
MySQL-style SHOW DATABASES statement
PostgreSQL-style by querying information_schema.schemata. For example:
SELECT schema_name FROM information_schema.schemata;
Once you have the database name, you can find the tables using either:
MySQL-style SHOW TABLES statement
PostgreSQL-style by querying information_schema.tables. For example:
SELECT table_name FROM information_schema.tables WHERE table_schema = '[database to check]';
Once you find the tables, you can get more information about them using SHOW COLUMNS FROM [table] or the information_schema database.
In postgresql, one can have all tables names by running the following query
SELECT table_name FROM information_schema.tables WHERE table_schema='public';
Is there something similar in monetdb to have the list of tables ?
I finally find this query
select tables.name from tables where tables.system=false ;
If you are using mclient, in the command line you could simply use the command "\d" to list all the tables in the current database.
sql> \d
TABLE sys.table1
TABLE sys.table2
TABLE sys.table3
Additionally, use the command "\d tablename" to view the metadata of a table - equivalent to "show create table" in mysql.
I would like to know how I can get the metadata of an object in a Vertica database; like metadata of a table. Is there any table that stores the metadata of objects (functions, views, tables) in Vertica Database.
For example in Oracle, I could type the following and get a detailed description of tables or see the code of a procedure.
oracle :> desc table_name;
or
oracle :> edit proc_name;
I know that I can see the tables from my schemas with \dt command, but is there any way I can see the DDL statements that created the objects?
Thanks, but this is not what I want. I was looking for is the export_objects() function:
select export_objects('','object_name')
This way you will get the creation script for the object.
\d table-name should get you what you need.
Extra tip: If you specify only the schema, you will get all of the objects inside that schema. Sure beats having to enter a loop where you run export_objects() for every object.