pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philippe Lang <philippe.lang@attiksystem.ch>
To: Marc G. Fournier <scrappy@postgresql.org>
To: pgsql-sql@postgresql.org
Subject: Re: Way to reverse ordering of an IP ... ?
Date: Wed, 6 Sep 2006 08:35:01 +0200
Message-ID: <6C0CF58A187DA5479245E0830AF84F421D1169@poweredge.attiksystem.ch> (raw)

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  

Attachments:

  smime.p7s (application/x-pkcs7-signature, 3.1K) download

view thread (2+ messages)

Message-ID: <6C0CF58A187DA5479245E0830AF84F421D1169@poweredge.attiksystem.ch>
Permalink:  ../6C0CF58A187DA5479245E0830AF84F421D1169@poweredge.attiksystem.ch/
Also on:    postgresql.org/message-id/6C0CF58A187DA5479245E0830AF84F421D1169@poweredge.attiksystem.ch

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: philippe.lang@attiksystem.ch, scrappy@postgresql.org
  Subject: Re: Way to reverse ordering of an IP ... ?
  In-Reply-To: <6C0CF58A187DA5479245E0830AF84F421D1169@poweredge.attiksystem.ch>
  References: <6C0CF58A187DA5479245E0830AF84F421D1169@poweredge.attiksystem.ch>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox