Re: Way to reverse ordering of an IP ... ?

From: "Philippe Lang" <philippe(dot)lang(at)attiksystem(dot)ch>
To: "Marc G(dot) Fournier" <scrappy(at)postgresql(dot)org>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Way to reverse ordering of an IP ... ?
Date: 2006-09-06 06:35:01
Message-ID: 6C0CF58A187DA5479245E0830AF84F421D1169@poweredge.attiksystem.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

pgsql-sql-owner(at)postgresql(dot)org wrote:

> for Reverse DNS purposes, I'd like to reverse an IP ...
>
> ie: 200.46.204.1 would become 1.204.46.200
>
> Is there an easy way of doing this *short* of writing a
> plpgsql function?
>
> I've checked the docs, and found the substring() function
> that allows for using a regex, which I thought might allow
> this, but can't seem to figure out a proper format for it ;(
>
> If I have to write a function to do it, fine ... just wanted
> to make sure I wasn't missing something first ...

Hi,

You can use (\d+)\.(\d+)\.(\d+)\.(\d+) for the match, and \4.\3.\2.\1 for the replacement in your Regexp.

Cheers,

----------------------------------
Philippe Lang, Ing. Dipl. EPFL
Attik System
rte de la Fonderie 2
1700 Fribourg
Switzerland
http://www.attiksystem.ch

Tel: +41 (26) 422 13 75
Fax: +41 (26) 422 13 76

Browse pgsql-sql by date

  From Date Subject
Next Message Andrew Sullivan 2006-09-06 11:31:13 Re: Query regarding to MS reporting services (Grand total problem)
Previous Message Dinesh Tiwari 2006-09-06 05:30:19 Query regarding to MS reporting services (Grand total problem)