postgresql - Why is SPLIT_PART working when I create a view but not when updating a table column?
问题描述
I've been using SPLIT_PART when creating views without issues and just tried updating a column in a table using the same syntax but am getting this error:
SQL Error [42601]: Unterminated string literal started at position 0 in SQL ', 0)). Expected char
From the following sql:
update table1
set email1 = split_part(emails_combined,';',1);
Why does this work when creating a view but not when updating a column in a table?
Is there a way I can get this to work in table? I have a column with a list of emails separated by semicolons that I want to split and fill separate columns with each email.
Update -- Here is a sample of the data in the column I'm trying to split:
testing@123.net;
;jon@loremipsum.com;jason@sample.net;test@123.com
jon@loremipsum.com;jason@sample.net;test@123.com
;testing@123.net
;info@loremipsum.com;misc@random.com;info@stuff.com
;
jon@loremipsum.com;jason@sample.net;test@123.com
There are rows where the only value is a ';'. There are no null rows.
Update: I randomly tried moving the closing ; down another line and the SQL worked. Like this:
update table1
set email1 = split_part(emails_combined,';',1)
;
Why would moving the closing semicolon like this make a difference?
解决方案
推荐阅读
- random - OpenOffice RAND() 函数 - 阻止它重新计算,直到被告知
- c++ - 如何使用唯一作用域枚举访问不同类型的不同数组?
- python - SQLAlchemy - 如何将数据库值(列)映射到我的值对象类?
- awk - 替换 Awk 数组中的索引,同时保持值的顺序不变
- pine-script - 自主前瞻测试
- mongodb - mongodb $and $lte 和 $gte 的操作对于整数值没有按预期工作
- vue.js - 如何制作切换列表 vue-select?
- python - 根据定义的总和限制拆分项目列表
- java - 错误“在类中找不到 main(String[]) 方法”
- javascript - 检查深层嵌套对象数组中的条件并返回父数组