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 [...]
Posts Tagged ‘select’
Inline CASE statement in PostgreSQL
Posted: 9th June 2010 by Tim in PostgreSQLTags: case, database, if, PostgreSQL, query, select, server, sql, statement, switch
0
Getting the insert ID in PostgreSQL
Posted: 9th February 2010 by Tim in PostgreSQLTags: insert, insert id, postrges, select, transaction
Quite often you need to insert a row into a table and then extract the auto-generated ID. Often people do the insert and then query the table again for the highest ID. This method may have concurrency issues (ie: if someone else inserts a record between the two queries), so they wrap it all up [...]
USE [schema_name] in PostgreSQL
Posted: 17th November 2009 by Tim in PostgreSQLTags: database, MySQL, PostgreSQL, select, SET, USE
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 [...]