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
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)
-
5Cast your text value to
::INET.'192.168.1.083'::INETshould be sufficient.Sean– Sean2011-06-01 19:53:25 +00:00Commented Jun 1, 2011 at 19:53
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.