On Sun, 30 Jan 2005 19:42:22 -0800, rasdj wrote: > I have a lot of SQL to convert to postgres from oracle. I have most of the > problems worked out except for this last bit. Many of my tables need the > last comma replaced with a close parenthesis - they look like this: > > create table schema.table ( > FLD000 NUMERIC(10,0) NOT NULL, > FLD001 CHAR(3) NOT NULL, > FLD002 DATE NOT NULL, > ; > > when the syntax requires: > > FLD002 DATE NOT NULL) > ; > > I output the text in reverse thinking I could find the semicolon, go to > the next line and replace the 'comma newline' with 'closeparen newline' > and then go on to find the next semicolon.
You don't give a heck of a lot of details here, but the first thing that leaps to mind is, * Suck it all into a string, let's call it "s". * s = s.replace(",\n;", ")\n;") * Dump out s. Failing that, regex can be used to allow for any whitespace, but worry about that if this isn't enough. We can also discuss trying to stream this operation if your SQL won't fit into memory all at once, but on modern machines that would be a breathtaking number of table definitions that would make me think you have other, larger problems :-) -- http://mail.python.org/mailman/listinfo/python-list