Postgres ts_vector

为君一笑 提交于 2020-02-08 07:26:04

问题


I am using Seqeulize with Nodejs.

My table name is "Users" and it has a column "userName". I have named the ts vectored column userNameVector. In trying to create the column and set the triggers, I keep getting the error "errorMissingColumn".

Apparently it is telling me that my column "userName" doesn't exist but I triple checked and it does.

The log from the node console is as follows:

Executing (default): ALTER TABLE "Users" ADD COLUMN "userNameVector" TSVECTOR
Executing (default): UPDATE "Users" SET "userNameVector" = to_tsvector('english', userName)
Executing (default): CREATE INDEX userName_search_idx ON "Users" USING gin("userNameVector");
Executing (default): CREATE TRIGGER userName_vector_update BEFORE INSERT OR UPDATE ON "Users" FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger("userNameVector", 'pg_catalog.english', userName)
{ [Error: column "username" does not exist]
  severity: 'ERROR',
  code: '42703',
  position: '62',
  file: 'parse_relation.c',
  line: '2655',
  routine: 'errorMissingColumn',
  sql: 'UPDATE "Users" SET "userNameVector" = to_tsvector(\'english\', userName)' }

回答1:


Looks like another case of misguided CaMeL case names.

Postgres identifiers are lower-cased by default. If you use non-standard names (legal, all lower-case) and double-quote them at creation, you have to double-quote them for the rest of their life. So:

"userName" instead of userName

Related:

  • The manual on identifiers
  • Prevent insert if condition is met


来源:https://stackoverflow.com/questions/25143566/postgres-ts-vector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!