incubator-empire-db-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Döbele <doeb...@esteam.de>
Subject re: Create table as
Date Fri, 19 Nov 2010 10:20:24 GMT
Hello Jorge,

actually no, but it is not hard to achieve.

Personally normally separate creating tables (DDL statements) from data manipulation statements
as you normally have a given table into which you want to insert your data.
Hence I normally solve it somewhat like this:

        // Define the table
        DBTable myTable = new DBTable("MYTABLE", db);
        myTable.addColumn(...);

        // Create the table
        DBSQLScript script = new DBSQLScript();
        db.getDriver().getDDLScript(DBCmdType.CREATE, myTable, script);
        script.run(db.getDriver(), conn, false);

        // now fill the table using "SELECT INTO ..."
        db.executeSQL(cmd.getInsertInto(myTable), conn);

if you want to do this in one step using CREATE TABLE ... AS SELECT ... you can to it as follows:

        // Define the table
        DBTable myTable = new DBTable("MYTABLE", db);
        myTable.addColumn(...);

        // Create and execute a "CREATE TABLE ??? AS SELECT ..."
        StringBuilder s = new StringBuilder();
        s.append("CREATE TABLE ");
        myTable.addSQL(s, DBExpr.CTX_NAME);
        s.append(" AS ");
        cmd.getSelect(s);
        db.executeSQL(s.toString(), conn);

This however is Oracle specific and won't work for other databases.

Regards
Rainer


Jorge Muñiz Morán wrote:
> from: Jorge Muñiz Morán [mailto:jorge.muniz@nortia-in.es] 
> to: empire-db-user@incubator.apache.org
> re: Create table as
>
> Hi everybody,
>
> This is the first mail that I send to the list so, first of all, I would like to thank
all the contributors of Empire-db for their awesome work!!
>
> I would like to know if 'create table as select' queries are supported in the latest
Empire version. I'm not able to find it anywhere.
>
> Many thanks in advance,
> Jorge Muñiz
> @jmunizmoran

Mime
View raw message