11

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?

2 Answers 2

17

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)
1
  • 5
    Cast your text value to ::INET. '192.168.1.083'::INET should be sufficient. Commented Jun 1, 2011 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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.