Absolute value on int2 or int4 field - Mailing list pgsql-sql

From Chris Johnson
Subject Absolute value on int2 or int4 field
Date
Msg-id Pine.LNX.4.00.9808271824330.31820-100000@boreus.bedfo.ma.tiac.net
Whole thread Raw
Responses Re: [SQL] Absolute value on int2 or int4 field
List pgsql-sql
I need to sort a list of entries by the absolute value of a particular
field.  I examined the documentation and found that @ is the operator that
I need, but it doesn't appear to work on int2 or int4 fields.

Anyone have any ideas on how to accomplish this?

cmj=> create table test (a int2, b int4, c float4, d float8);
CREATE
cmj=> insert into test values (1,1,1,1);
INSERT 246399 1
cmj=> insert into test values (-2,-2,-2,-2);
INSERT 246400 1
cmj=> select * from test order by @a;
ERROR:  parser: parse error at or near "@"
cmj=> select * from test order by @b;
ERROR:  parser: parse error at or near "@"
cmj=> select @a from test;
ERROR:  Can't find left op: @ for type 21
cmj=> select @b from test;
ERROR:  Can't find left op: @ for type 23
cmj=> select @c from test;
?column?
--------
       1
       2
(2 rows)

cmj=> select @d from test;
?column?
--------
       1
       2
(2 rows)


If you've got an idea please feel free to enlighten me!

Chris

PS I'm tempted to just convert the fields to floating point, but that
   seems to easy.  ;-)


pgsql-sql by date:

Previous
From: "Bryan White"
Date:
Subject: Re: [SQL] copy one to many?
Next
From: Walt Bigelow
Date:
Subject: Re: [SQL] copy one to many?