生成指定长度的随机字符串在Google Cloud SQL和/或BigQuery中如何实现?

huangapple go评论63阅读模式
英文:

How to generate random string of specific length in Google Cloud SQL and/or Bigquery?

问题

I'm trying to update a table that has missing data with some unique strings, that I try to generate randomly.

SELECT CODE_POINTS_TO_BYTES(
[CAST(FLOOR(100RAND()) AS INT64),
CAST(FLOOR(100
RAND()) AS INT64),
CAST(FLOOR(100RAND()) AS INT64),
CAST(FLOOR(100
RAND()) AS INT64)]) AS bytes;

This is what I've tried but I'm getting the following error:

生成指定长度的随机字符串在Google Cloud SQL和/或BigQuery中如何实现?

英文:

I'm trying to update a table that has missing data with some unique strings, that I try to generate randomly.

SELECT CODE_POINTS_TO_BYTES(
  [CAST(FLOOR(100*RAND()) AS INT64), 
  CAST(FLOOR(100*RAND()) AS INT64), 
  CAST(FLOOR(100*RAND()) AS INT64), 
  CAST(FLOOR(100*RAND()) AS INT64)]) AS bytes;

This is what I've tried but I'm getting the following error:

生成指定长度的随机字符串在Google Cloud SQL和/或BigQuery中如何实现?

答案1

得分: 0

看起来在添加第四个参数时出现了问题,它能够查询到第三个转换。

生成指定长度的随机字符串在Google Cloud SQL和/或BigQuery中如何实现?

并且在添加第四个参数时捕获了相同的错误。

正如 @nbk 提到的,您可以尝试使用 uuid

> 选择 GENERATE_UUID() AS uuid;

英文:

It looks like it is having problems when adding the fourth parameter.it is able to query up to the 3rd cast.

生成指定长度的随机字符串在Google Cloud SQL和/或BigQuery中如何实现?

and captures the same error when added the 4th parameter.

As @nbk mentioned you can try using uuid

> SELECT GENERATE_UUID() AS uuid;

huangapple
  • 本文由 发表于 2023年5月17日 17:30:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76270580.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定