0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Postgresの引数配列

0
Posted at

ストアド引数でinteger[]とnumeric[]があるような場合に
型が自動識別できないというエラーが発生するけどその対処方法。

def strSql = "{call hogehoge(argInt := ?, argNum := ?)}"
def params = [sql.connection.createArrayOf('int4', [1] as BigDecimal[])
		, sql.connection.createArrayOf('numeric', [1] as BigDecimal)]
sql.call(strSql, params) {
}

ググッたけどこういう事例ってなくてぶっちゃけ勘で書いたものなので
もうちょっといいやり方がありそうな気がするけどとりあえずこのやり方で出来た。
原理は分かってないけどとりあえず動く。

ポイントはcreateArrayOfでPostgresqlの型を指定する事と
引数の配列をBigDecimal[]にする事。
多分後者に関してはもっといいやり方があると思うけど
単純に[1]としただけではダメだった。

値([1] as BigDecimal[])の部分はspockでwhereで用意した名称を指定する事も出来る。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?