How to define two relationships to the same table in SQLAlchemy

As of version 0.8, SQLAlchemy can resolve the ambiguous join using only the foreign_keys keyword parameter to relationship. publish_user = relationship(User, foreign_keys=[publishing_user_id], backref=backref(‘pages’, order_by=id)) edit_user = relationship(User, foreign_keys=[last_edit_user_id]) Documentation at http://docs.sqlalchemy.org/en/rel_0_9/orm/join_conditions.html#handling-multiple-join-paths

Count the Null columns in a row in SQL

This method assigns a 1 or 0 for null columns, and adds them all together. Hopefully you don’t have too many nullable columns to add up here… SELECT ((CASE WHEN col1 IS NULL THEN 1 ELSE 0 END) + (CASE WHEN col2 IS NULL THEN 1 ELSE 0 END) + (CASE WHEN col3 IS NULL … Read more

Why are the queries in SQL mostly written in Capital Letters?

It was meant for readability. Before, SQL was written in plain-text editors (no syntax/code highlighting) and keywords needed to be differentiated for better readability and maintenance. SELECT column_name FROM table_name WHERE column_name = column_value vs select column_name from table_name where column_name = column_value See the difference? The first word in each line told the reader … Read more

Google Sign-In, Database Side

Create a EXTERNAL_ID column, and use it to store the identifier from the external system. You should add an EXTERNAL_TYPE column and set that to ‘GOOGLE’.. when you go to integrate further authentication-providers, this can be set to different values (eg ‘OPEN_ID’, ‘FACEBOOK’.) When interfacing with external systems, it is always necessary to store the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)