Skip to content

Tag: sql

Calculate age in MySQL (InnoDB)

If I have a person’s date of birth stored in a table in the form dd-mm-yyyy, and I subtract it from the current date, what format is the date returned in? How can I use this returned format to calculate someone’s age? Answer If the value is stored as a DATETIME data type: Less precise when you con…

Caching SQL queries

If I look in my profiler for SQL-server, it comes up with a lot of duplicate queries such as: A lot of these queries are not needed to display real time data, that is, if someone inserted a new record that was matched in that query it wouldn’t matter if it didn’t display for up to an hour after in…

Importing records from PostgreSQL to MySQL

Was wondering if anyone had any insight or recommended tools for exporting the records from a PostgreSQL database and importing them into a MySQL database. I believe the table structure is 100% identical. Thoughts? Thanks! Answer The command will generate SQL-standard-compliant INSERT statements with all colu…

PostgreSQL visual interface similar to phpMyAdmin?

I’d like to view and possibly edit tables for PostgreSQL visually like phpMyAdmin, where you can see the list of tables, and fields and individual rows for a table. Is there any utility that can do this? Forgive me if this is actually possible in pgAdmin III, but I couldn’t figure out any way to s…

sqlite variables

Greetings! I am using SQLite. I want to declare variable, but it gives me a syntax error. Please help me to find a solution: Select * from t2 where value= ? This is my query. Now how can I pass …

Select NULL Values in SQLAlchemy

Here’s my (PostgreSQL) table — I want to select all people that are not known to be married, i.e., including those with NULL marriage_status. This does not work — Of course this does — The problem is that I’m accessing it from SQLAlchemy with — which gets translated to &#82…