Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

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)
share|improve this answer
    
Ah, thanks, I only tried with "192.168.1.082". –  Jonas Jun 1 '11 at 11:04
    
Cast your text value to ::INET. '192.168.1.083'::INET should be sufficient. –  Sean Jun 1 '11 at 19:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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