Обсуждение: What would be a good way to append some text to the end of a text field?
Now I use php3 to read the text from the database then I append some text to it and finaly I do an update on the text field. Is it possible to use an SQL statement to do this directly in the database? Thanks Wim. I use: Posgresql 6.5.3 Linux 5.2 PHP3
Вложения
Re: [GENERAL] What would be a good way to append some text to the end of a text field?
От
"Ross J. Reedstrom"
Дата:
On Mon, Nov 22, 1999 at 02:45:04PM +0100, Wim Aarts wrote:
>
> Now I use php3 to read the text from the database then I append some
> text to it and finaly I do an update on the text field.
> Is it possible to use an SQL statement to do this directly in the
> database?
>
Like this?
test=> create table test_text (word_id int, words text);
CREATE
test=> insert into test_text values (1, 'some text');
INSERT 684150 1
test=> insert into test_text values (2, 'some other text');
INSERT 684151 1
test=> select * from test_text;
word_id|words
-------+---------------
1|some text
2|some other text
(2 rows)
test=> update test_text set words = textcat(words,', and text added later') where word_id=1;
UPDATE 1
test=> select * from test_text;word_id|words
-------+-------------------------------
2|some other text
1|some text, and text added later
(2 rows)
test=>
Ross
--
Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St., Houston, TX 77005
Thanks Ross,
Sorry I didn't come with an example but I meant something like:
test=> create table test_text (word_id int, words text);
CREATE
test=> insert into test_text values (1, 'some text');
INSERT 684150 1
test=> UPDATE test_text SET words = words + 'some more text' WHERE word_id = 1;
Resulting in:
test=> SELECT * FROM test_text;
word_id|words
-------+---------------
1|some text some more text
Hope this explains my question.
Thanks.
"Ross J. Reedstrom" wrote:
> On Mon, Nov 22, 1999 at 02:45:04PM +0100, Wim Aarts wrote:
> >
> > Now I use php3 to read the text from the database then I append some
> > text to it and finaly I do an update on the text field.
> > Is it possible to use an SQL statement to do this directly in the
> > database?
> >
>
> Like this?
>
> test=> create table test_text (word_id int, words text);
> CREATE
> test=> insert into test_text values (1, 'some text');
> INSERT 684150 1
> test=> insert into test_text values (2, 'some other text');
> INSERT 684151 1
> test=> select * from test_text;
> word_id|words
> -------+---------------
> 1|some text
> 2|some other text
> (2 rows)
>
> test=> update test_text set words = textcat(words,', and text added later') where word_id=1;
> UPDATE 1
> test=> select * from test_text;word_id|words
> -------+-------------------------------
> 2|some other text
> 1|some text, and text added later
> (2 rows)
>
> test=>
>
> Ross
> --
> Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu>
> NSBRI Research Scientist/Programmer
> Computer and Information Technology Institute
> Rice University, 6100 S. Main St., Houston, TX 77005
Вложения
Sorry Ross, I replied to early, the second example covers it.....Oops Wim. "Ross J. Reedstrom" wrote: > On Mon, Nov 22, 1999 at 02:45:04PM +0100, Wim Aarts wrote: > > > > Now I use php3 to read the text from the database then I append some > > text to it and finaly I do an update on the text field. > > Is it possible to use an SQL statement to do this directly in the > > database? > > > > Like this? > > test=> create table test_text (word_id int, words text); > CREATE > test=> insert into test_text values (1, 'some text'); > INSERT 684150 1 > test=> insert into test_text values (2, 'some other text'); > INSERT 684151 1 > test=> select * from test_text; > word_id|words > -------+--------------- > 1|some text > 2|some other text > (2 rows) > > test=> update test_text set words = textcat(words,', and text added later') where word_id=1; > UPDATE 1 > test=> select * from test_text;word_id|words > -------+------------------------------- > 2|some other text > 1|some text, and text added later > (2 rows) > > test=> > > Ross > -- > Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu> > NSBRI Research Scientist/Programmer > Computer and Information Technology Institute > Rice University, 6100 S. Main St., Houston, TX 77005