On 01/02/2016 01:02 PM, Krishnakant wrote: > hello all, > I wish to know how I can pick up the constraint failure errors in my code? > I think I would probably have to pick up the errors in a try: except: > system?
that is correct. > But What is the exact way of picking up the message? You'd need to catch the type of exception, such as IntegrityError which is usually what you will get for a constraint violation. Beyond that, if you need to programmatically have more information you'd need to parse the text of the exception with a regular expression. > Do we have a ready made exception for each constraint? the Python DBAPI has these exceptions: https://www.python.org/dev/peps/pep-0249/#exceptions how each DBAPI driver uses these exceptions and for what messages is not strongly defined and is different not just for every possible database but also somewhat different for the different drivers on a single target database. SQLAlchemy catches these exceptions and re-throws them exactly as they are inside of a same-named wrapper, so instead of catching say psycopg2.IntegrityError you can catch sqlalchemy.exc.IntegrityError instead. But the text inside is still copied from whatever the driver sends. > i am using Alchemy with Psycopg2 for postgresql 9.4 > Happy hacking. > Krishnakant. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.