Re: Way to reverse ordering of an IP ... ? - Mailing list pgsql-sql

From Philippe Lang
Subject Re: Way to reverse ordering of an IP ... ?
Date
Msg-id 6C0CF58A187DA5479245E0830AF84F421D1169@poweredge.attiksystem.ch
Whole thread Raw
In response to Way to reverse ordering of an IP ... ?  ("Marc G. Fournier" <scrappy@postgresql.org>)
List pgsql-sql
pgsql-sql-owner@postgresql.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

pgsql-sql by date:

Previous
From: Dinesh Tiwari
Date:
Subject: Query regarding to MS reporting services (Grand total problem)
Next
From: Andrew Sullivan
Date:
Subject: Re: Query regarding to MS reporting services (Grand total problem)