From: | Sondaar Roelof <roelof(dot)sondaar(at)scania(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | How to cast text to cidr/inet |
Date: | 2001-03-15 10:29:00 |
Message-ID: | F28A2B83DFE0D411A7B3006097487147468FDB@sv7007.scania.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hello,
I am battleling around to get a text field into a cidr and inet type field.
The documentation says things like CAST(val AS text) but inet and cidr does
not seem to exist.
However the following works:
dhcp=# insert into dhcp_subnet(ipaddress) values('139.122.172/18');
INSERT 46172 1
dhcp=# select * from dhcp_subnet;
id | ipaddress | description
----+----------------+-------------
2 | 139.122.128/18 |
(1 row)
But the copying from table to table (text to cidr) does not work.
Perhaps someone can give me some clues.
Additional information (tables, queries, results are below).
Best regards,
Roelof Sondaar
WM-data Zwolle B.V.
Russenweg 5
P O Box 391
8000 AJ ZWOLLE
The Netherlands
* roelof(dot)sondaar(at)wmdata(dot)nl
* +31 (0) 384 977 366
*******************************************************
Disclaimer
This email is confidential and intended solely for the use of
the individual to whom it is addressed. Any views or opinions
presented are solely those of the author and do not
necessarily represent those of WM-data Zwolle B.V.
If you are not the intended recipient, be advised that you
have received this email in error and that any use,
dissemination, forwarding, printing or copying of this email
is strictly prohibited.
If you have received this email in error please notify
WM-data Zwolle B.V. Helpdesk by telephone on
+31(0)384 977 319
*******************************************************
Some additional information:
dhcp=# \d dhcp_subnet
Table "dhcp_subnet"
Attribute | Type | Modifier
-------------+---------+----------------------------------------------------
--
id | integer | not null default
nextval('dhcp_subnet_id_seq'::text)
ipaddress | cidr |
description | text |
Indices: dhcp_subnet_id_key,
dhcp_subnet_ipaddress_idx
dhcp=# \d dhcp_subnet_hp
Table "dhcp_subnet_hp"
Attribute | Type | Modifier
-------------+------+----------
ipaddress | text |
description | text |
dhcp=# INSERT INTO dhcp_subnet(
dhcp(# ipaddress,
dhcp(# description)
dhcp-# SELECT
dhcp-# ipaddress,
dhcp-# description
dhcp-# FROM dhcp_subnet_hp;
ERROR: Attribute 'ipaddress' is of type 'cidr' but expression is of type
'text'
You will need to rewrite or cast the expression
dhcp=# INSERT INTO dhcp_subnet(
dhcp(# ipaddress,
dhcp(# description)
dhcp-# SELECT
dhcp-# CAST(ipaddress AS cidr),
dhcp-# description
dhcp-# FROM dhcp_subnet_hp;
ERROR: Cannot cast type 'text' to 'cidr'
From | Date | Subject | |
---|---|---|---|
Next Message | datactrl | 2001-03-15 11:03:53 | Some questions about PLpgSql |
Previous Message | Richard Huxton | 2001-03-15 07:39:18 | Re: need to join successive log entries into one |