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?
PostgreSQL allows a type of integer type namely SMALLINT . It requires 2 bytes of storage size and can store integers in the range of -37, 767 to 32, 767. It comes in handy for storing data like the age of people, the number of pages in a book, etc. Syntax: variable_name SMALLINT.
serial (or serial4) creates integer columns. bigserial (or serial8) creates bigint columns. smallserial (or serial2) creates smallint columns.
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
This seems to work:
CAST(X'3e000000' AS INT)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With