Pentaho(勺子):在SQL中生成许多行的主键


林老爷的日常
2025-02-09 01:29:54 (1月前)


我有一个案例:将数据从Access数据库传输到SQL。我遇到过如何在SQL中创建大量新主键的问题。

当我转移previos表时,我使用了Generator ……

4 条回复
  1. 0# 真不错 | 2019-08-31 10-32



    而不是创建随机密钥,使用序列将数字序列转换为高基数(例如使用javascript

    id_as_char = id_as_int.toString(36)

    )。



    当然,你有其他方法!







  2. 1# 电动少女 | 2019-08-31 10-32



    谢谢你的帮助。我在字符串之前添加了一行来添加“0”。




    1. id = id.toString(36)
      while (id.length < (5 || 2)) {id = 0 + id;}

    2. </code>



    00zzm
    00zzn
    00zzo
    00zzp
    00zzq
    00zzr
    00zzs
    00zzt
    00zzu
    00zzv
    00zzw
    00zzx
    00zzy
    00zzz
    01000
    01001
    01002
    01003
    01004
    01005
    01006
    01007
    01008
    01009
    0100a
    0100B



    就是这样

    https://gist.github.com/endel/321925f6cafa25bbfbde




    1. Number.prototype.pad = function(size) {
      var s = String(this);
      while (s.length < (size || 2)) {s = 0 + s;}
      return s;
      }

    2. (1).pad(3) // => “001”
      (10).pad(3) // => “010”
      (100).pad(3) // => “100”

    3. </code>

  3. 2# 猫南北 | 2019-08-31 10-32



    为什么不把序列处理留给sql server?你在使用哪个数据库?
    如果您使用mysql或postgres,您可以创建一个具有串行类型的新列,并且在db级别处创建此序列唯一连续编号将更好。




    https://www.postgresql.org/docs/9.5/static/datatype-numeric.html#DATATYPE-SERIAL


登录 后才能参与评论