getDBTableDDL
First introduced in version 3.00.6
Syntax
getDBTableDDL(dbHandle,tableName)
Details
Gets the table creation statement for the specified table in the target database.
-
The target database must be a DFS database.
-
A user can get the table creation statement only if at least one of the following conditions is met:
-
The user is a DolphinDB administrator (admin).
-
The user has the management permission (DB_MANAGE) on the target database.
-
The user is the owner (DB_OWNER) of the target database.
-
The user has read (TABLE_READ), write (TABLE_WRITE), insert (TABLE_INSERT), update (TABLE_UPDATE), or delete (TABLE_DELETE) permission on the target table.
-
Parameters
dbHandle is a STRING scalar or database object that specifies the target database.
tableName is a STRING scalar that specifies the target table.
Returns
A STRING scalar that indicates the table creation statement.
Examples
Example 1: Create the dfs://olap_table database and the pt partitioned table, and get the table creation statement. You can execute the statement directly by using runScript. In the following example, the table schemas created in the two operations (schema1 and schema2) are identical.
dbName="dfs://olap_table"
db=database(dbName, VALUE, 1..5, engine="OLAP")
schematb = table(1:0, idvalts, [INT, DOUBLE, TIMESTAMP]) pt=createPartitionedTable(db, schematb, pt, `id)
schema1=pt.schema()
DDL=getDBTableDDL(db, "pt")
DDL
/*Output:
create table "dfs://olap_table"."pt"(
id INT,
val DOUBLE,
ts TIMESTAMP
) partitioned by id*/
dropTable(db,"pt")
runScript(DDL)
schema2=(loadTable("dfs://olap_table", "pt")).schema()
runScript. In the
following example, the table schemas created in the two operations (schema1 and
schema2) are
identical.if(!existsCatalog("test")){
createCatalog("test")
}
if(size(exec schema from getSchemaByCatalog("test") where schema = "olap_table") > 0){
dropSchema("test", "olap_table")
}
use catalog test
create database olap_table partitioned by VALUE(1..5), engine="OLAP"
go
create table olap_table.pt (
id INT,
val DOUBLE,
ts TIMESTAMP
)
partitioned by id
schema1=olap_table.pt.schema()
dbUrl = exec dbUrl from getSchemaByCatalog("test") where schema = "olap_table"
db=database(dbUrl[0])
DDL=getDBTableDDL(db, "pt")
DDL // The DFS path in the output is randomly generated and is for reference only.
/*Output:
'create table "dfs://test_olap_table_1781024086061"."pt"(
id INT,
val DOUBLE,
ts TIMESTAMP
)
partitioned by id'*/
dropTable(db,"pt")
runScript(DDL)
schema2=olap_table.pt.schema()Related functions: database, createPartitionedTable, runScript, getDatabaseDDL
