Absolute value on int2 or int4 field

From: Chris Johnson <cmj(at)inline-design(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Absolute value on int2 or int4 field
Date: 1998-08-27 22:35:55
Message-ID: Pine.LNX.4.00.9808271824330.31820-100000@boreus.bedfo.ma.tiac.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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. ;-)

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Walt Bigelow 1998-08-28 03:06:16 Re: [SQL] copy one to many?
Previous Message Bryan White 1998-08-27 19:56:22 Re: [SQL] copy one to many?