incubator-empire-db-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jorge Muñiz Morán <jorge.mu...@nortia-in.es>
Subject Re: Create table as
Date Fri, 19 Nov 2010 12:25:06 GMT
Hi Rainer, thank you very much for your quick reply.

We also separate creating tables from data manipulation as you have said
but, in an specific case, we need to do it in one step.

We are using Empire-db into a Groovy project so what we have done is to
create a category which, depending on the DBDatabaseDriver, generates the
appropiate query (Oracle) or throws an UnsupportedOperationException
(Others, here we do it in two steps)

Once again, many thanks for your help,

Cheers,
Jorge Muñiz
@jmunizmoran

2010/11/19 Rainer Döbele <doebele@esteam.de>

> 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