Skip to content
Advertisement

SQLAlchemy alternative names for table columns

I know my question must be very simple but I couldn’t find any straight answer to it.

I am mapping a table with SQlAlchemy :

JavaScript
  1. How to I set up an label for the existing columns above to avoid they current name with spaces?

  2. Bonus question : What is the advantage of mapping as as class instead of mapping as table given that their content/efforts are similar (but a little bigger in class)?

Edit extra doubt:

Can you tell me what is wrong with this statement so I can´t use it for a simple select where? stmt = select(chicago_schools_manual).where(chicago_schools.columns['Name of School'] == 'Charles').limit(20)

JavaScript

If i use it by the way suggested it works :

JavaScript

Advertisement

Answer

You can use key="some_name" to refer to columns by a name that is different from the actual column name in the table. For example,

JavaScript

re: bonus question – See

What is the difference between SQLAlchemy Core and ORM?

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement