Re: Using COPY

From: "Joel Burton" <joel(at)joelburton(dot)com>
To: "Peter Darley" <pdarley(at)kinesis-cem(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using COPY
Date: 2002-05-15 15:06:04
Message-ID: JGEPJNMCKODMDHGOBKDNMEFNCOAA.joel@joelburton.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Well, you could, with something like

UPDATE tblFoo SET foo=
substring(foo from 1 for (position('@@~@@' in foo))-1) || '\n' ||
substring(foo from (position('@@~@@' in foo))+5) where foo like '%@@~@@%';

(Try saying that ten times fast! :) )

P.S. Fix the +5 above to match the length of the marker string.

> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org
> [mailto:pgsql-general-owner(at)postgresql(dot)org]On Behalf Of Peter Darley
> Sent: Tuesday, May 14, 2002 6:15 PM
> To: Joel Burton
> Cc: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] Using COPY
>
>
> Joel,
> Darn, I was hoping it was possible to do it with just SQL. :)
> Thanks,
> Peter Darley
>
> -----Original Message-----
> From: Joel Burton [mailto:joel(at)joelburton(dot)com]
> Sent: Tuesday, May 14, 2002 3:11 PM
> To: Peter Darley
> Cc: pgsql-general(at)postgresql(dot)org
> Subject: RE: [GENERAL] Using COPY
>
> create function fix_marker(text) returns text as '
> $_ = shift;
> s/@@~@@/\\n/;
> return $_;
> ' language 'plperl';
>
> update tblFoo set foo=fix_marker(foo) where foo like '%@@~@@%';
>
> would do nicely. Or you could do it in plpython, plruby (if installed), or
> plperl.
>
> You could do it in plpgsql with a combination of ugly left || right with
> strpos, but it's a lot easier in languages that have string-replace
> functions.
>
> - J.
>
> Joel BURTON | joel(at)joelburton(dot)com | joelburton.com | aim: wjoelburton
> Knowledge Management & Technology Consultant
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2002-05-15 15:06:12 Re: Spped of max
Previous Message Bill Gribble 2002-05-15 14:56:45 (security) Rules of thumb for escaping user input?