Re: update problem

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: update problem
Date: 2009-05-14 05:19:02
Message-ID: 20090514051902.GA25647@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

In response to Paul Alarcon :
> hello in using postgres 8.3 on windows and i have aproblem to update a table,
> this is the facts, I have a tables where i want to update the name based on a
> lenght of a field for instance i want to update all the rows where the the
> substring(cuenta from 17 for 40) is equal around all the table may you have an
> idea how i could made it
> thanks a lot

I'm not sure if i understand you, but how about

test=*# select * from foobar;
id | name
----+-----------
1 | 123
2 | 123abc123
3 | 234abc234
4 | 345abc345
5 | 123456789
(5 rows)

-- change all the trings contains substring 'abc' from 4-6 position to
-- 'hit'

test=*# update foobar set name='hit' where substr(name, 4, 3)='abc';
UPDATE 3
test=*# select * from foobar;
id | name
----+-----------
1 | 123
5 | 123456789
2 | hit
3 | hit
4 | hit
(5 rows)

HTH, Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Ilya Urikh 2009-05-14 06:56:54 Re: C-Language function invocation from another one.
Previous Message Ridvan Lakas ng Bayan S. Baluyos 2009-05-14 01:52:41 Re: tablespace question