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 3 years have passed since last update.

Postgresがカラム名を小文字で見に行く

Posted at

下記のSELECT文を作ったら、メインのSELECT文の方で「"rowNo"というカラムが見つからねぇ」と言われた。(WITHの中は正常終了)
ASで「rowNo」と名前を付けても意地でも「rowno」をを探しに行く模様。
しょうがないので一旦スネークケースにした。

参考:https://blog.goo.ne.jp/toritori0318/e/3aa9009ac512dbb5becff0bc2098cd1c

--- 誤 ---
WITH 商品_G AS
(
  SELECT
    ROW_NUMBER() OVER(ORDER BY 商品.unit_cd ASC NULLS LAST) AS "rowNo",
    SUM(商品.num) AS "sumNum",
    商品.unit_cd AS "unitCd"
  FROM
    shouhin AS 商品
  WHERE
     商品.no = 'xxx'
  GROUP BY
    商品.unit_cd
  ORDER BY
    商品.unit_cd ASC NULLS LAST
  LIMIT ALL OFFSET 0
)
SELECT
    商品_G.rowNo
    商品_G.sumNum
    商品_G.unitCd
    名称情報.name
FROM 商品_G
LEFT JOIN 名称マスタ 名称情報 ON
(
     AND UNM.name_cd = 商品_G.unitCd
)

--- 正 ---
WITH 商品_G AS
(
  SELECT
    ROW_NUMBER() OVER(ORDER BY 商品.unit_cd ASC NULLS LAST) AS "row_no",
    SUM(商品.num) AS "sum_num",
    商品.unit_cd
  FROM
    shouhin AS 商品
  WHERE
     商品.no = 'xxx'
  GROUP BY
    商品.unit_cd
  ORDER BY
    商品.unit_cd ASC NULLS LAST
  LIMIT ALL OFFSET 0
)
SELECT
    商品_G.row_no AS "rowNo",
    商品_G.sum_num AS "sumNum",
    商品_G.unit_cd AS "unitCd",
    名称情報.name AS "unitName"
FROM 商品_G
LEFT JOIN 名称マスタ 名称情報 ON
(
     AND UNM.name_cd = 商品_G.unit_cd
)

0
0
2

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?