Обсуждение: vecor/list INSERT or UPDATE

Поиск
Список
Период
Сортировка

vecor/list INSERT or UPDATE

От
Adam Kornick
Дата:
SQL Gurus,

I want to update a specific set of rows in a column with a list or
vector.  Something like,

UPDATE some_table SET col = [1 2 3 4 5]
        WHERE some_condition_limits_to_five_rows;

but all I see UPDATE accepting is a scalar ("5") not a vector or list
("1 2 3 4 5")...is this even possible?

Thanks,
Adam


---
Here's a clearer (hopefully) but longer example

RPGSL_ROW_NUMBER   SOME_VARIABLE

4                       12
5                       13
6                       14
7                       14
8                       14


SOME_VARIABLE to be replaced with 1:5 using UPDATE so that we get


RPGSL_ROW_NUMBER   SOME_VARIABLE

4                       1
5                       2
6                       3
7                       4
8                       5






Adam

Re: vecor/list INSERT or UPDATE

От
Richard Huxton
Дата:
Adam Kornick wrote:
>
> SQL Gurus,
>
> I want to update a specific set of rows in a column with a list or
> vector.  Something like,
>
> UPDATE some_table SET col = [1 2 3 4 5]
>         WHERE some_condition_limits_to_five_rows;

Sorry mate - no, not on any system I can think of either. How is the
system supposed to know which row gets which value? What happens when
your condition returns six rows?

You've got two options: wrap five update statements in a transaction (if
you want to know they all succeed/fail as a group) or build some
procedural solution.

- Richard Huxton