Posts Tagged ‘database’

PHP is able to communicate with PostgreSQL databases using some relatively simple calls. In a similar manner to other database systems, the script needs to do the following: connect to the database using pg_connect execute queries using pg_query and pg_free_result close the database connection using pg_close For example, consider the following script: <?PHP // database […]

Conditional INSERT in SQL

Posted: 23rd October 2013 by Tim in SQL
Tags: , , , , , ,

Sometimes you want to run an INSERT statement in SQL only if some condition is met. There are a few methods available to do this, but not all of them are supported by all database systems. One method which is supported on all systems the use of a SELECT statement to return the row values, […]

It’s often useful to concatenate two fields together in an SQL query. In PostgreSQL, fields may be concatenated using the || operator. The syntax is really simple. Just place the double bar between the fields you want to join, and (optionally) give a label to that new field. Strings can also be concatenated with the […]

PostgreSQL, unfortunately, does not provide an inline IF statement like some other SQL servers. CASE statements, however, can be run inline which can be quite handy. Let’s say you have a user table with a num_heads field. You want to know if the user is a zombie, human or alien with one query. This could […]

USE [schema_name] in PostgreSQL

Posted: 17th November 2009 by Tim in PostgreSQL
Tags: , , , , ,

For those moving from MySQL to PostgreSQL, there are a few differences which you will need to get used to. One of these differences is the USE command, used to select the schema to select tables, views, etc from. PostgreSQL does not have the USE command. Instead, you can use: SET search_path TO [schema_name] For […]

MySQL comes with a library to make talking to MySQL with C easyish. There are a few things you have to install first, though. I’m using Ubuntu 8.04 for this walkthrough, but things should be similar for other flavours of Linux. Before we start, we have to download the development files required: sudo apt-get install […]