如何使用Rails在Postgres中转义保留字列?

时间:2019-03-14 07:56:54

标签: ruby-on-rails postgresql

我在shift_breaks表下有一个名为“ length”的整数列。通过ruby访问该列可以正常工作,但是当尝试使用.where查询该列时,不会返回期望的结果。.

我尝试了各种绕过它的方法,但是找不到不涉及重命名列的解决方案。任何帮助将不胜感激。

# Application details

Rails: 5.1.6.2
Ruby: 2.5.3
PostgreSQL: 9.6.10

enter image description here

2 个答案:

答案 0 :(得分:0)

length在ruby和psql中不是保留字。检查此链接以了解psql-reserved words in postgresql中的保留字。请用error发布您的where query

答案 1 :(得分:0)

enter image description here

这最终成为模型中的问题。 <div class="content"> <!-- *LEFT * --> <div class="left"> <div class="swiper-container"> <div class="swiper-wrapper"> <!--【Left】page_1 --> <div class="swiper-slide"> <div class="page_1 lefts"> <section class="name"> <p class="title">title_1</p> <p class="data">data_1</p> </section> <section class="spec"> <p class="title">title_11</p> <p class="data">data_11</p> </section> <section class="skill"> <p class="title">title_111</p> <ul class="data"> <li class="tool"> <figure class="Illustrator"> <img class="meter" src="https://placehold.jp/0/5305a6/5305a6/44x44.png?text=_" alt="advanced" /> <img class="meter-t" src="https://placehold.jp/0/0570a6/0570a6/22x22.png?text=_" alt="Illustrator" /> <figcaption>Illustrator</figcaption> </figure> <figure class="Photoshop"> <img class="meter" src="https://placehold.jp/0/5305a6/5305a6/44x44.png?text=_" alt="intermediate" /> <img class="meter-t" src="https://placehold.jp/0/0570a6/0570a6/22x22.png?text=_" alt="Photoshop" /> <figcaption>Photoshop</figcaption> </figure> <figure class="Indesign"> <img class="meter" src="https://placehold.jp/0/5305a6/5305a6/44x44.png?text=_" alt="elementary" /> <img class="meter-t" src="https://placehold.jp/0/0570a6/0570a6/22x22.png?text=_" alt="Indesign" /> <figcaption>Indesign</figcaption> </figure> <figure class="Vectorworks"> <img class="meter" src="https://placehold.jp/0/5305a6/5305a6/44x44.png?text=_" alt="intermediate" /> <img class="meter-t" src="https://placehold.jp/0/0570a6/0570a6/22x22.png?text=_" alt="Vectorworks" /> <figcaption>Vectorworks</figcaption> </figure> <figure class="Shade"> <img class="meter" src="https://placehold.jp/0/5305a6/5305a6/44x44.png?text=_" alt="intermediate" /> <img class="meter-t" src="https://placehold.jp/0/0570a6/0570a6/22x22.png?text=_" alt="Shade" /> <figcaption>Shade</figcaption> </figure> </li> <li class="code"> <figure class="HTML"> <img class="meter" src="https://placehold.jp/0/5305a6/5305a6/44x44.png?text=_" alt="elementary" /> <img class="meter-t" src="https://placehold.jp/0/0570a6/0570a6/22x22.png?text=_" alt="HTML" /> <figcaption>HTML</figcaption> </figure> <figure class="CSS"> <img class="meter" src="https://placehold.jp/0/5305a6/5305a6/44x44.png?text=_" alt="elementary" /> <img class="meter-t" src="https://placehold.jp/0/0570a6/0570a6/22x22.png?text=_" alt="CSS" /> <figcaption>CSS</figcaption> </figure> <figure class="Javascript"> <img class="meter" src="https://placehold.jp/0/5305a6/5305a6/44x44.png?text=_" alt="beginner" /> <img class="meter-t" src="https://placehold.jp/0/0570a6/0570a6/22x22.png?text=_" alt="Javascript" /> <figcaption>Javascript</figcaption> </figure> <figure class="PHP"> <img class="meter" src="https://placehold.jp/0/5305a6/5305a6/44x44.png?text=_" alt="beginner" /> <img class="meter-t" src="https://placehold.jp/0/0570a6/0570a6/22x22.png?text=_" alt="PHP" /> <figcaption>PHP</figcaption> </figure> </li> </ul> </section> <section class="hobby"> <p class="title">title_1111</p> <p class="data">data_1111</p> </section> </div> </div> <!-- /【Left】page_1 --> <!--【Left】page_2 --> <div class="swiper-slide"> <div class="page_2 lefts"> <section class="thisis"> <p class="title">title_2</p> <p class="data">data_2</p> </section> <section class="Q"> <p class="title">title_22</p> <p class="data">data_22</p> </section> </div> </div> <!-- /【Left】page_2 --> <!--【Left】page_3 --> <div class="swiper-slide"> <div class="page_3 lefts"> <section class="thatis"> <p class="title">title_3</p> <p class="data">data_3</p> </section> </div> </div> <!-- /【Left】page_3 --> </div> </div> </div> <!-- *MIDDLE *--> <div class="middle"> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide"> <!-- 【middle】page_1 --> <div class="page_1 middles"> <img class="imgs" src="https://placehold.jp/45/a60518/ffffff/411x480.png?text=1" width="411" /> </div> </div> <div class="swiper-slide"> <!-- 【middle】page_2 --> <div class="page_2 middles"> <img class="imgs" src="https://placehold.jp/45/1b05a6/ffffff/411x411.png?text=2" width="411" /> </div> </div> <div class="swiper-slide"> <!-- 【middle】page_3 --> <div class="page_3 middles"> <img class="imgs" src="https://placehold.jp/45/3da605/ffffff/411x76.png?text=3" width="411" /> </div> </div> </div> </div> </div> <div class="swiper-pagination"></div> <!-- *RIGHT * --> <div class="right"> <div class="swiper-container"> <div class="swiper-wrapper"> <!-- 【right】page_1 --> <div class="swiper-slide"> <div class="page_1 rights"> <section class="attributes"> <p class="title">title_11111</p> <p class="data">data_11111</p> <p class="data">data_11111</p> </section> <section class="umm"> <p class="title">title_111111</p> <div class="data"> <img src="https://placehold.jp/0/a6a605/a6a605/193x202.png?text=_" width="193" /> <span class="data">data_111111</span> </div> </section> </div> </div> <!-- /【right】page_1 --> <!--【right】page_2 --> <div class="swiper-slide"> <div class="page_2 rights"> <section class="theme"> <p class="title">title_222</p> <p class="data">data_222</p> </section> </div> </div> <!-- /【right】page_2 --> <!--【right】page_3 --> <div class="swiper-slide"> <div class="page_3 rights"> </div> </div> <!-- /【right】page_3 --> </div> </div> </div>正在使用before_validation调用方法-阻止记录在数据库中更新... = _ =


enter image description here

长度为20的换档符实际上在数据库中是什么样子。