10

I would like to insert an IP-address into a column that has type inet. In what format can I insert the data? is it only binary or is there any way I can insert from text e.g. "192.168.1.082"? Are there any help-functions for this so I can test it from psql in the command prompt?

15

It seems pretty easy:

postgres=# create table inet_test (address inet);

CREATE TABLE

postgres=# insert into inet_test values ('192.168.2.1');

INSERT 0 1

postgres=# insert into inet_test values ('192.168.2.1/24');

INSERT 0 1

postgres=# select * from inet_test;


 address
----------------
 192.168.2.1
 192.168.2.1/24
(2 rows)
  • Ah, thanks, I only tried with "192.168.1.082". – Jonas Jun 1 '11 at 11:04
  • 2
    Cast your text value to ::INET. '192.168.1.083'::INET should be sufficient. – Sean Jun 1 '11 at 19:53
0

Make sure when you placing any STRINGS in POSTGRES with SINGLE QUOTES.

If you use DOUBLE QUOTES you will get errors, and this is a very common mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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