Re: [sqlalchemy] Re: How to check for table's existance without a separate query

2019-12-04 Thread James Fennell
> However I cannot catch for this error, I can only catch for "sqlalchemy.exc.ProgrammingError". Why is that? James On Wed, Dec 4, 2019 at 6:03 PM Jonathan Vanasco wrote: > > Personally, I would handle the check like this: > > ERRORS_UNDEFINED_TABLE = (psycopg2.errors.UndefinedTable, ) > >

Re: [sqlalchemy] Re: How to check for table's existance without a separate query

2019-12-04 Thread Jonathan Vanasco
Personally, I would handle the check like this: ERRORS_UNDEFINED_TABLE = (psycopg2.errors.UndefinedTable, ) try: res = conn.execute(stmt) except sa.exc.ProgrammingError as err: if isinstance(err.orig, ERRORS_UNDEFINED_TABLE): print('Table does not exist') raise This

Re: [sqlalchemy] Re: How to check for table's existance without a separate query

2019-12-04 Thread Zsolt Ero
Thanks. So is the following code correct for psycopg2 specific scenario? try: res = conn.execute(stmt) except sa.exc.ProgrammingError as err: if isinstance(err.orig, psycopg2.errors.UndefinedTable): print('Table does not exist') else: raise err -- SQLAlchemy - The

Re: [sqlalchemy] Re: How to check for table's existance without a separate query

2019-12-04 Thread Simon King
Rather than looking at the string representation, you could inspect the "orig" attribute of the SQLAlchemy exception: https://docs.sqlalchemy.org/en/13/core/exceptions.html#sqlalchemy.exc.DBAPIError Simon On Wed, Dec 4, 2019 at 5:52 PM Zsolt Ero wrote: > > My best idea so far is > > if

[sqlalchemy] Re: How to check for table's existance without a separate query

2019-12-04 Thread Zsolt Ero
My best idea so far is if 'psycopg2.errors.UndefinedTable' in str(err) Just to note, I'm looking especially for psycopg2.errors.UndefinedTable, I'm not using any other DB. On Wednesday, 4 December 2019 18:37:02 UTC+1, Zsolt Ero wrote: > > Hi, > > I'm looking for a way to check for a table's

Re: [sqlalchemy] Manage encryption on arbitrary column type

2019-12-04 Thread Hameer Abbasi
Thanks. Yes, that's enough for my use-case, more than enough, to be honest. Out of curiosity, how would you do it for a native ENUM? Thanks a lot! On Wednesday, December 4, 2019 at 4:09:36 PM UTC+1, Mike Bayer wrote: > > > > On Wed, Dec 4, 2019, at 7:57 AM, Hameer Abbasi wrote: > > Hello. I've

[sqlalchemy] How to check for table's existance without a separate query

2019-12-04 Thread Zsolt Ero
Hi, I'm looking for a way to check for a table's existance. I know I can do it in 2 queries, once for checking the table and one for running the query, but I'd prefer to do it in one query with a try-except block. What is the best way to do this? I'm using psycopg2 and I see that the raised

Re: [sqlalchemy] Manage encryption on arbitrary column type

2019-12-04 Thread Mike Bayer
On Wed, Dec 4, 2019, at 7:57 AM, Hameer Abbasi wrote: > Hello. I've created an encryption wrapper that marshals things in and out of > encryption, except that for the TypeDecorator the input and output type are > different. I'm having trouble wrapping float and Enum types while still >

Re: [sqlalchemy] Assigning SQL expression to a version column.

2019-12-04 Thread Mike Bayer
On Wed, Dec 4, 2019, at 3:02 AM, Jeff Horemans wrote: > > > What is the expected behavior of assigning an SQL expression to a version > column? > Before migrating from version 1.2.4. to 1.3.3. the priority was given to the > assigned expression, afterwards it seems to be the other way

Re: Automating charset encoding/collation conversion for MySQL db.

2019-12-04 Thread Mike Bayer
On Tue, Dec 3, 2019, at 7:50 PM, Jens Troeger wrote: > Hello, > > Using a MySQL database keeping Unicode strings under control turned out to be > a bit of a challenge. I could have sworn that character encoding and > collation

[sqlalchemy] Manage encryption on arbitrary column type

2019-12-04 Thread Hameer Abbasi
Hello. I've created an encryption wrapper that marshals things in and out of encryption, except that for the TypeDecorator the input and output type are different. I'm having trouble wrapping float and Enum types while still keeping them queryable. Can someone take a look at the attached

Re: [sqlalchemy] Configure autovacuum_vacuum_scale_factor on a PG table

2019-12-04 Thread Simon King
On Wed, Dec 4, 2019 at 12:13 PM Jordan Pittier wrote: > > Hi, > I am looking for a way to describe, in my Python model, that a table should > have autovacuum_vacuum_scale_factor and autovacuum_analyze_scale_factor set > to a non-default value. Similar to what the following statement would do: >

[sqlalchemy] Configure autovacuum_vacuum_scale_factor on a PG table

2019-12-04 Thread Jordan Pittier
Hi, I am looking for a way to describe, in my Python model, that a table should have autovacuum_vacuum_scale_factor and autovacuum_analyze_scale_factor set to a non-default value. Similar to what the following statement would do: ALTER TABLE public.XX SET (autovacuum_vacuum_scale_factor =

[sqlalchemy] Assigning SQL expression to a version column.

2019-12-04 Thread Jeff Horemans
What is the expected behavior of assigning an SQL expression to a version column? Before migrating from version 1.2.4. to 1.3.3. the priority was given to the assigned expression, afterwards it seems to be the other way around. I think there is something to say about both, but I wanted to check