Thanks for helping me out everyone. I ended up simply using the numeric type (I didn't realize it could support such large numbers) and writing the hex-to-numeric conversion functions in my application code.
On Thu, Apr 10, 2014 at 09:13:47PM +0800, Olivier Lalonde wrote: > I was wondering if there would be any way to do the following in PostgreSQL: > > UPDATE cryptotable SET work = work + 'some big hexadecimal number' > > where work is an unsigned 256 bit integer. Right now my column is a > character varying(64) column (hexadecimal representation of the number) but > I would be happy to switch to another data type if it lets me do the > operation above. > > If it's not possible with vanilla PostgreSQL, are there extensions that > could help me? > > -- > - Oli > > Olivier Lalonde > http://www.syskall.com <-- connect with me! >
Hi Olivier,
Here are some sample pl/pgsql helper functions that I have written for other purposes. They use integers but can be adapted to use numeric.
Regards, Ken --------------------------- CREATE OR REPLACE FUNCTION hex2dec(t text) RETURNS integer AS $$ DECLARE r RECORD; BEGIN FOR r IN EXECUTE 'SELECT x'''||t||'''::integer AS hex' LOOP RETURN r.hex; END LOOP; END $$ LANGUAGE plpgsql IMMUTABLE STRICT; ---------------------------
--------------------------- CREATE OR REPLACE FUNCTION bytea2int ( in_string BYTEA ) RETURNS INTEGER AS $$