#postgres
12 posts tagged postgres. Clear filter
-
Select Basename in Postgres SQL
Postgres doesn't have a basename function per se. But it's easy to accomplish. select regexpreplace('http://www.seanbehan.com/images/logo.png', '.+/', '') ; -- Will return logo.png
-
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 Use Named Variables with Postgres and PHP PDO Driver
You can write reusable scripts with Postgres by taking advantage of named variables. A named variable starts with a : in your sql script. Here is an example select :anumber You can then use this...
-
Connect to Postgres on Heroku using DATABASE_URL Config Var with PHP and PDO
Unfortunately PHP's PDO constructor doesn't take a database connection url (in a format that Heroku makes available as a config var) as an argument. It has its own, rather odd syntax. However, it's...
-
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 Import/Export a Database from One Heroku App to Another Heroku App
Heroku is awesome! Let's say we want to copy a production database to a staging database. We can use the pg:backups:restore command to accomplish this. Here is an example. For the source database...
-
How To Create a Dump File in Postgres Compatible with Heroku
When Heroku creates a dump file of your Postgres database it uses the -Fc option It is equivalent to running pgdump -Fc -d nameofdb nameofdb.dump This command will let you import your database with...
-
How to Enable UUIDs in Postgres
The first thing you'll need to do is enable the extension create extension "uuid-ossp"; To test that it's working select uuidgeneratev1(); For more info on which version of the algorithm you should...
-
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 Install Pyscopg2 Python Postgres Driver on Mac OSX with Homebrew, Postgres.app and VirtualEnv
You might have to append the path of the Postgres.app bin directory to your path in order to install the Python driver for Posgres. export PATH=$PATH:/Applications/Postgres.app/Contents/MacOS/bin...
-
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...