#databases
15 posts tagged databases. Clear filter
-
How to Find Postgres Log File and Postgres Data Directory from PSQL
If you want to find the location of your log file in Postgres, you'll need to hop into a Psql session.. psql dbname Then it's as simple as running.. show data\directory ; Which will output the data...
-
How to Just Get SQL Statement Error with SQLAlchemy Python Database Wrapper
If you're working with SQLAlchemy, the best database driver for Python, and want to see only SQL syntax errors, you need to use the StatementError exception class. On it, is an attribute orig, that...
-
How to Log and Query SQL Queries Hitting Your Database with MySQL
Here is some code just in case you want to look at and query the queries hitting your MySQL database. Enter this from the mysql client console. mysql SET GLOBAL logoutput = 'TABLE' mysql SET GLOBAL...
-
Simple SQL for Counting New Signups
Here is a little snippet that will return new signups (or new records) for today select id, email, createdat::date date from signups where email not in (select distinct email from signups where...
-
How to Make Cross Database Queries with Postgres and DBLink Extension
Here are a few snippets for cross database queries. It's important to note that you must be explicit in enumerating the columns and types you are querying. Otherwise, things will probably not work...
-
How to Resolve ERROR 1396 (HY000): Operation CREATE USER failed for Error in MySQL
If you run into this error when trying to create a user in mysql, chances are you already have this user account created. create user 'someuser'@'localhost' identified by 'somepassword'; ERROR 1396...
-
Extract Domain Names From Links in Text with Postgres and a Single SQL Query
This query and pattern will return urls in text all within a single SQL query. select substring(columnname from '.://([^/])') as domainname from tablename; And here it is in a larger query, say for...
-
How To Fix ActiveRecord::ConnectionTimeoutError with Sinatra
If you get this error message ActiveRecord::ConnectionTimeoutError could not obtain a database connection within 5.000 seconds (waited 5.001 seconds) Try closing the connection after each request...
-
How To Remove Duplicates From a Table with Postgres
Let's create a table that will hold some dummy data. create table fruits (id serial primary key, name varchar, color varchar); insert into fruits (name, color) values ('apple', 'red'); insert into...
-
How to cast a string of comma separated numbers into an array of integers for Postgres
If you have an string of numbers like and you want to turn it into an array of integers you need to cast it into an integer array type. This is commonly used together when grabbing a set using the...
-
How To Export A MySQL Database to JSON, CSV and XML with Ruby and the ActiveRecord Gem
It's trivial to export data from a mysql database with Ruby and ActiveRecord. All you have to do is establish a connection and define a class that represents the table. require 'rubygems' require...
-
Backup and Rotate MySQL Databases Simple Bash Script
Make a directory ( it can anywhere ) called baks/mysql mkdir -p /baks/mysql Create a file (it can be anywhere) called /root/mysqlbackups.sh and put this script in it !/bin/bash modify the following...
-
Dump MySQL Database without Drop Table Syntax
Output .sql file for MySQL but without the drop table syntax before table name use the --skip-add-drop-table flag
-
Managing Timestamps in MySQL with a Trigger
MySQL doesn't support having two columns with time stamping on both initialization and/or on updating at the same time. It would be nice to be able to do \this\ where the created\at column gets the...
-
Install do_mysql Ruby Gem on Mac OS X
I ran into the same problem when installing mysql gem for Rails development. This fix worked for me http://seanbehan.com/programming/fixing-mysql-for-rails-2-2-development-on-mac-os-x/ The same...