Hi Ted,
You can use migrations API to perform this operation, as you will have database
independent code. e.g. Inside upgrade() method of your migration class:
ERXMigrationTable newTable = database.newTableNamed("NEW_TABLE");
newTable.new*Column("ColumnName", ...); // depending upon what type of column
it is.
newTable.create();
// if there is any primary key, then
// newTable.setPrimaryKey("ColumnName"); // This will take care of the
sequence, index, uniqueness etc.
// Use sql script file to insert data into newTable from existingTable...
ERXMigrationTable existingTable = database.existingTabe("EXISTING_TABLE");
existingTable.existingColumnNamed("ColumnName").delete();
Farrukh
On 2010-12-04, at 5:21 AM, Theodore Petrosky wrote:
> I am using migrations to normalize my postgresql backend. I needed to factor
> out some columns into a new table. the only way I thought of was to use the
> COPY command to a file then read the file back into my new table.
>
> /*
> * copies the data out to the file then
> * copies it back to the new table
> */
>
> ERXJDBCUtilities.executeUpdate(database.adaptorChannel(),
> "COPY (select id, c_invoice_number, c_invoice_date, c_invoice_booked_date,
> 't', " +
> "'f' from t_version where c_is_invoiced) " +
> "TO '/Users/asacksadmin/Desktop/selectedInvoices.txt'");
>
>
> ERXJDBCUtilities.executeUpdate(database.adaptorChannel(),
> "COPY t_invoice (c_version_id, c_invoice_number, c_invoice_date,
> c_invoice_booked_date, " +
> "c_is_final_invoice, c_is_partial_invoice) " +
> "FROM '/Users/asacksadmin/Desktop/selectedInvoices.txt'");
>
>
> /*
> * drops the columns from the version table that are
> * no longer used
> *
> * c_invoice_booked_date
> * c_invoice_number
> * c_invoice_date
> *
> */
>
> ERXJDBCUtilities.executeUpdate(database.adaptorChannel(),
> "ALTER TABLE t_version drop COLUMN c_invoice_booked_date");
>
> ERXJDBCUtilities.executeUpdate(database.adaptorChannel(),
> "ALTER TABLE t_version drop COLUMN c_invoice_number");
>
> ERXJDBCUtilities.executeUpdate(database.adaptorChannel(),
> "ALTER TABLE t_version drop COLUMN c_invoice_date");
>
> so i got it to work and I am thinking, "Is there a better way?" Of course
> this leaves behind the file selectedInvoices.txt on the desktop but that is
> the only artifact left over.
>
> Maybe it's not so bad after all. but I thought I would ask. "Is there a
> better way?"
>
> Ted
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list ([email protected])
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/webobjects-dev/farrukh.ijaz%40fuegodigitalmedia.com
>
> This email sent to [email protected]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]