Re: Auomatic numbering, replacing nulls and IF

From: "Gregory Wood" <gregw(at)com-stock(dot)com>
To: "PostgreSQL-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Auomatic numbering, replacing nulls and IF
Date: 2002-03-20 15:32:09
Message-ID: 00bd01c1d024$987eee60$7889ffcc@comstock.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> 1) Is it possible to create an INT PRIMARY KEY column that automagically
> numbers itself? MS-SQL does this using the IDENTITY keyword.

As you already mentioned, SERIAL/SEQUENCEs.

> 2) The ISNULL function in both Oracle and MS-SQL takes 2 numbers and
returns
> the second if the first is null, otherwise it returns the first. ISNULL in
> Postgres seems to be something quite different. Before I go writing my own
> function to do it, is there one already?

I think you're looking for coalesce():

"COALESCE(value[, ...])
The COALESCE function returns the first of its arguments that is not NULL.
This is often useful to substitute a default value for NULL values when data
is retrieved for display, for example:

SELECT COALESCE(description, short_description, '(none)') ...'

> 3) How do I do 'IF this_sql THEN that_sql'? I keep getting:
> parse error at or near "IF"

I'm not sure exactly what you need... but it sounds a lot like CASE:

http://postgresql.overtone.org/users-lounge/docs/7.2/postgres/functions-cond
itional.html

Greg

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Keller 2002-03-20 15:32:23 no quotes in arrays in 7.2
Previous Message Jan Wieck 2002-03-20 15:26:47 Re: Passing parameters to triggers