Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Postgress problem 1

Status
Not open for further replies.

Lee2

Technical User
Aug 12, 2002
11
US
Sorry to bother you with Postgress problem in ANSI-SQL
forum, but I didn't find any good postgress forum, so i hope someone here is able to help me.

I have problem with with NULLs.


My problem is as follows:
I have for example this table:

id | timestamps
---------------
1 | 9999343
---------------
2 |
---------------
3 | 9993434
--------------
4 |

where blank spaces are NULLs, and timestamps are unix timestamps.
Now I want to select value from my_table so that when the resulting row contains something, it will return 1 and when it is NULL the select will return 0

So I want this result:

1
_

0
_

1
_

0

I have tried almost everything but i CANNOT substitute NULLs
with 0 (or anything else, except NULL). It colud be done with the help of UNIONs but i am not allowed to use them, because after using UNION i cannot order the result.

Is postgress able to do any operation with NULLs?

for example: select col1 + 1 from table;

if the number in the col1 is a number, postgres will add 1 to that number. But if it is NULL it will return NULL, even if I explicitely cast NULL to type integer.

I have tried to apply many functions to critical column, but every function which i tried returned NULL instead anything else.




 
does postgres support a function called NVL or ISNULL the functions generally are in the format

nvl(myfield,0) which is a short cut for

return the value of myfield if it is not null otherwise return 0

or

does postgres support a case statement in a select
as in

select case myfield is null then 0 else 1 end as myvalue from mytable etc....

 
thank you very much, it can be done with the case clausule.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top