tags:

views:

957

answers:

2

I have a big list of hexadecimal numbers I'd like to insert into a PostgresQL table. I tried something like this:

INSERT INTO foo (i)
VALUES (0x1234);

...but that didn't work. Is this possible?

+1  A: 

This seems to work:

 CAST(X'3e000000' AS INT)
mike
+1  A: 

As you've noted, you can start with a bit-string constant written in hexadecimal, and then type-cast it to the type you want. So,

INSERT INTO foo (i) VALUES (CAST(x'1234' AS int))

or

INSERT INTO foo (i) VALUES (x'1234'::int) -- postgres-specific syntax
Rob Kennedy