24

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?

3 Answers 3

26

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
10

This seems to work:

 CAST(X'3e000000' AS INT)
4

You can just use

x'1234'::int;

For more information see my post on,

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.