in reply to Inserting in an unknown point
Parsing SQL is not trivial, but if these statements are generated by a program, there's a good chance they're consistently simple enough that you can use a regex to do what you want. Assuming your constraint names aren't quoted (so they will match \w), and that the entire clause never breaks over two lines, this should work:
(I haven't tested this code, BTW.) You can adjust this if you have quotes, and so on, but the basic idea is to match around it and then re-write it to what you want.$sql =~ s/ \bADD\s+CONSTRAINT\s+ # lead-in to clause (\w+)\s+ # the constraint name \( # opening paren of column list / ADD CONSTRAINT $1 FOREIGN KEY ( /x;
HTH
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Inserting in an unknown point
by curtisb (Monk) on Oct 04, 2002 at 17:36 UTC |