Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with ampersands in index name #11

Closed
bbigras opened this issue Dec 18, 2012 · 3 comments
Closed

Problem with ampersands in index name #11

bbigras opened this issue Dec 18, 2012 · 3 comments
Assignees

Comments

@bbigras
Copy link

bbigras commented Dec 18, 2012

I have some indexes with ampersands in their names. I had to modify the output.sql from :

CREATE UNIQUE INDEX item_uom_conv&item_no&ix3 ON [...]

to :

CREATE UNIQUE INDEX "item_uom_conv&item_no&ix3" ON [...]

to make it work with psql (9.2.2).

@ghost ghost assigned darold Dec 18, 2012
@darold
Copy link
Owner

darold commented Dec 18, 2012

Hi Bruno,

Yes all objects name with non alphanumerics characters (and some other) need to be double-quoted by hand. But here I think thay in an index name you may rename the index instead and remove the ampersand.

@bbigras
Copy link
Author

bbigras commented Dec 18, 2012

I wish the manual would have warned me about that but it's no big deal.

For now, since I'm only testing and I have about 50 indexes with an ampersand, I'm using the following python script:

import re
with open('output.sql', 'r') as f_in:
    with open('output2.sql', 'w') as f_out:
        for line in f_in:
            f_out.write(re.sub(r'(CREATE.*INDEX )(.*)( ON)', r'\1"\2"\3', line))

@bbigras bbigras closed this as completed Dec 18, 2012
@darold
Copy link
Owner

darold commented Dec 18, 2012

You can also use this single command line:

perl -p -i -e 's/(CREATE.INDEX )(.)( ON)/\1"\2"\3/' output.sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants