English 中文(简体)
如何通过一个阵列,让 p子客户使用最不受干扰的功能?
原标题:How to pass an array to node s pg client for being used by an unnest() function?

我想能够改变名单的位置。 每个清单都有自己的立场。 在我更新名单时,我想把这一资料留给数据库。 因此,我通过一个阵列,在正确的次序中填好清单,并利用一个中度复杂的问题来更新清单:

with pos as (
    select 
        id as pos_id,
        row_number() over() as position
    from (
        select unnest(
            array[36, 33, 35, 37, 46, 39, 40, 41, 43, 45, 38, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 58, 59, 60, 61, 62, 65, 66, 67, 68, 78, 79, 82, 83]
        ) as id 
    ) a 
)  
update lists l
    set position = pos.position
from 
    pos
where 
    l.id = pos.pos_id

这完全在pg_admin中,但当我试图在Node将这项工作提上去时,它刚刚赢得了工作。

I ve tried to send $1 parameter using these forms:

  1. unnest($1)
  2. unnest($1::bigint[])
  3. unnest($1:list)
  4. unnest(ARRAY[$1])
  5. unnest(ARRAY[$1::bigint[])
  6. unnest(ARRAY[$1::list)
  7. unnest(ARRAY[$1::bigint[])
  8. unnest(ARRAY[ + positions.join( , ) + ])
  9. unnest( { + positions.join( , ) + } )
  10. unnest( { + positions.join( , ) + } ::bigint[])

无。 其中有些人回去了一种 par差错,有些是“必须添加明确的类型”。 我如何通过一个阵列来汇集。 本案中的问题?

问题回答

I should have made some mistake when I tried. Because option 2, unnest($1::bigint) worked fine as I was trying to confirm all forms one by one.

So the correct code is:

let positions = [36, 33, 35, 37, 46, 39, 40, 41, 43, 45, 38, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 58, 59, 60, 61, 62, 65, 66, 67, 68, 78, 79, 82, 83];

pool.query( with pos as ( select id as pos_id, row_number() over() as position from ( select unnest($1::bigint[]) as id ) a )  update listas l set position = pos.position from pos where l.id = pos.pos_id ,
    [positions], (error) => {
... whatever




相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签