Western and Eastern name orders can be a PITA, particularly when titles and honorifics come into play.

西方和东方的名称顺序可以成为PITA,尤其是在冠名和荣誉称呼起作用时。

The application I’m currently working on is a database of articles from a military magazine. Most of the authors are Hungarians, meaning they have a reversed name order. Many of them are also holding military ranks which have to be displayed. Others are Westerners, some with ranks and honorifics, some without. Some of them are fighter pilots, and they use their nicknames (callsigns) in writing. Not all of them though. At the end of the day it’s a completely random heap of names, titles, nicknames and honorifics, and I have to put this into order.

我目前正在使用的应用程序是一个军事杂志的文章数据库。 大多数作者是匈牙利人,这意味着他们的名字顺序颠倒了。 他们中许多人还拥有必须显示的军事队伍。 其他人则是西方人,有些人具有行列和荣誉,有些则没有。 其中一些是战斗机飞行员,他们以书面形式使用昵称(呼号)。 虽然不是全部。 归根结底,这是一堆完全随机的名字,头衔,昵称和荣誉称号,我必须将其整理好。

Here are some examples:

这里有些例子:

Tőrös István is the editor-in-chief with a very basic Hungarian name: last name first, and first name last. A few other languages, for example Japanese or Korean also follow this reversed name order.

Tőrös István ( Tőrös István是主编,他的名字非常匈牙利语:姓氏在前,姓氏在后。 其他几种语言(例如日语或韩语)也遵循此相反的名称顺序。

Varga Csaba Béla is another Hungarian name, but with two given names (or as we call them, Christian names). We don’t call it a middle name like in English, but “second given name”.

Varga Csaba Béla是匈牙利的另一个名字,但有两个给定名称(或我们称之为基督教名称)。 我们不像英语那样称呼它为中间名,而是“第二个给定名称”。

Hadi "Dino" István is a Hungarian fighter pilot who used his nickname when signing his articles. Therefore it should be displayed.

Hadi "Dino" István ( Hadi "Dino" István是匈牙利的战斗机飞行员,在签署文章时使用了自己的昵称。 因此,应该显示它。

Dr. Kositzky Attila altbgy. is another military officer and pilot, but he used his scientific title and military rank (Brigadier General) and no nickname.

Dr. Kositzky Attila altbgy. 是另一名军官和飞行员,但他使用了自己的科学头衔和军衔(准将),没有昵称。

(I wonder how long it will take for some of them to find this article and wonder how their names became examples in a coding tutorial.)

(我想知道其中一些人需要多长时间才能找到本文,并且不知道他们的名字在编码教程中如何成为示例。)

This diversity may already be enough to make your head spin, but let’s throw a few foreigners into the mix:

这种多样性可能已经足以使您旋转,但让我们将一些外国人加入其中:

Anatoly Nikolaevich Kvochur is Russian, so he of has a “middle name” called a patronymic. He’s also a military officer, but doesn’t use his rank when writing.

Anatoly Nikolaevich Kvochur是俄罗斯人,因此他有一个“中间名”,称为“赞助人”。 他也是军官,但写作时不使用职级。

Gen. Chuck Yeager does though. He has a Western name, first name and last name in “proper” order (for Westerners at least) and here we have the rank before the name, not after it like for Hungarians.

Gen. Chuck Yeager 。 他有一个西方名字,名字和姓氏(至少对于西方人来说),按“适当的”顺序排列,在这里,我们在名字前拥有排名,而匈牙利人则没有。

Let’s bring a really fancy person into the pool, although he never wrote any articles for this magazine:The Right Honourable Mr. Justin Pierre James Trudeau, Prime Minister of Canada. This guy has not one, but three titles, and two middle names! Yikes! How would you handle that?!

让我们带一个真正想像的人,尽管他从未为该杂志写过任何文章: The Right Honourable Mr. Justin Pierre James Trudeau, Prime Minister of Canada. 这个家伙没有一个,而是三个头衔和两个中间名! kes! 您将如何处理?

If your application is English only, it’s a little bit easier. As a general rule, foreign names in English should be written using Western name order. For example my own name would be Tamas Polgar and not Polgár Tamás. In many other languages however, including Hungarian, the original name order is retained, so Donald Trump will never become Trump Donald. Titles and ranks will still follow Hungarian customs though: President Donald Trump will be Donald Trump elnök. Let’s just ignore the problem of translating titles and ranks for now.

如果您的应用程序仅是英语,那会容易一些。 通常,英语的外国名称应使用西方名称顺序书写。 例如,我自己的名字叫Tamas Polgar而不是Polgár Tamás 。 但是,在许多其他语言中,包括匈牙利语,都保留了原始名称顺序,因此Donald Trump永远不会成为Trump Donald 。 头衔和职级仍然会遵循匈牙利的习俗: President Donald Trump将是Donald Trump elnök 。 现在让我们忽略翻译标题和等级的问题。

The solution

解决方案

To retrieve names in correct order you can code some lengthy processing function in your backend, but it’s easier to teach PostgreSQL to do it for you.

要以正确的顺序检索名称,您可以在后端中编写一些冗长的处理函数,但是教PostgreSQL为您执行此操作会更容易。

Here is the structure of my authors table:

这是我的authors表的结构:

CREATE TABLE IF NOT EXISTS topgun.authors (  id serial NOT NULL PRIMARY KEY,  title character varying NOT NULL DEFAULT '',  first_name character varying NOT NULL,  middle_name character varying NOT NULL DEFAULT '',  last_name character varying NOT NULL,  rank character varying NOT NULL DEFAULT '',  nickname character varying NOT NULL DEFAULT '',  name_order numeric NOT NULL DEFAULT 0);

Only first_name and last_name are mandatory. The name_order field is a flag with the value of 0 for Eastern and 1 for Western name order. We are going to ignore multiple middle names because technically they’re one string, so a single field, middle_name will serve just fine for them. The same goes for multiple titles and ranks. We have title and rank separated because the first will always stay at the beginning of the name (Mr., Dr., etc.) but the other one may vary.

只有first_namelast_name是必需的。 name_order字段是一个标志,东方名称顺序为0 ,西方名称顺序为1 。 我们将忽略多个中间名,因为从技术上讲它们是一个字符串,因此单个字段middle_name将对它们middle_name 。 多个标题和等级也是如此。 我们将titlerank分开,因为第一个始终会保留在名称的开头(先生,博士等),但是另一个可能会有所不同。

Here’s how we’ll retrieve the names.

这是我们检索名称的方法。

Western order:Long: title rank first_name middle_name nickname last_nameShort: first_name middle_name last_name

西方顺序:长: title rank first_name middle_name nickname last_name短: first_name middle_name last_name

Eastern order:Long: title, last_name, nickname, middle_name, first_name, rankShort: last_name, first_name, middle_name

东部顺序:长: title, last_name, nickname, middle_name, first_name, rank短:首名last_name, first_name, middle_name

Let’s create or query:

让我们创建或查询:

SELECT  *FROM topgun.authorsORDER BY last_name, first_name, id

One of the reasons to store first, middle and last names separately is to simplify ordering, but it’ll also come handy when implementing a search function.

分别存储名字,中间名和姓氏的原因之一是简化排序,但是在实现搜索功能时也将很方便。

Now let’s extend our query with a conditional.

现在让我们用条件查询扩展查询。

SELECT  *,  (CASE WHEN(name_order = 1)    THEN               CONCAT(        (first_name || ' '),        (CASE WHEN (middle_name <> '')          THEN (middle_name || ' ')        END),        last_name      )    ELSE      CONCAT(                        (last_name || ' '),        (first_name),        (CASE WHEN (middle_name <> '')          THEN (' ' || middle_name)          END)        )    END) AS nameFROM topgun.authorsORDER BY last_name, first_name, id

The result will now contain a field called name which contains the name of the person in proper order.

现在,结果将包含一个名为name的字段,其中包含按正确顺序排列的人的姓名。

CONCAT means string concatenation. In Western name order, which is the first branch of the CASE WHEN condition, it concatenates first_name, middle_name and last_name. There’s another CASE WHEN in it because we don’t want to add the middle name if the person doesn’t have one. The same happens in the ELSE branch, which means Eastern name order, but the fields are concatenated in a different order. In both cases the field values are also concatenated with a space character either before or after the value, as required.

CONCAT表示字符串连接。 按照西方名称顺序(这是CASE WHEN条件的第一个分支),它连接first_namemiddle_namelast_name. 其中还有另一种CASE WHEN ,因为如果此人没有名字,我们不想添加中间名。 在ELSE分支中也会发生同样的情况,这意味着东部名称顺序,但是字段以不同顺序连接在一起。 在这两种情况下,都可以根据需要在值之前或之后用空格字符将字段值连接在一起。

The full name of the person with titles, nicknames, etc. works the same way, but it’s a little more complicated. I’m only showing the conditional here:

具有标题,昵称等的人的全名以相同的方式工作,但要复杂一些。 我只在这里显示条件:

(CASE WHEN (name_order = 1)  THEN    CONCAT(                      (CASE WHEN (title <> '')        THEN (title || ' ')      END),                          (CASE WHEN (rank <> '')        THEN (rank || ' ')      END),                          (first_name || ' '),                         (CASE WHEN (middle_name <> '')        THEN (middle_name || ' ')      END),                                      (CASE WHEN (nickname <> '')        THEN ('"' || nickname || '" ')      END),                          last_name                    )  ELSE    CONCAT(      (CASE WHEN (title <> '')        THEN (title || ' ')      END),                          (last_name || ' '),      (CASE WHEN (nickname <> '')        THEN ('"' || nickname || '" ')      END),      (CASE WHEN (middle_name <> '')        THEN (middle_name || ' ')      END),      first_name,      (CASE WHEN (rank <> '')        THEN (' ' || rank)      END)              )                   END) AS full_name

Aaand magic! The query now returns full names in proper name order! Nicknames will be displayed in quotes.

阿兰德魔术! 查询现在以正确的名称顺序返回全名! 昵称将显示在引号中。

If you let your fields take a NULL value, simply add IS NOT NULL to your conditions like this:

如果让您的字段采用NULL值,只需将IS NOT NULL添加到您的条件中,如下所示:

(CASE WHEN (middle_name IS NOT NULL AND middle_name <> '')  THEN (middle_name || ' ')END),

Of course this can be polished even further, but you probably got the idea.

当然这可以进一步完善,但是您可能知道了。

翻译自: https://medium.com/developer-rants/getting-names-in-the-right-order-with-postgresql-704104cf8fde


http://www.taodudu.cc/news/show-4571202.html

相关文章:

  • matlab中读取blf数据路径,需求可拆分车辆路径优化模型与BLF-GA算法设计
  • 从“弃儿”到大神,神经网络之父Hiton说人类就是非常精美的机器 | AI英雄
  • 技术分享 | UUID 很火但性能不佳?今天我们细聊一聊
  • 痴人、信徒、先驱:Hinton、LeCun、Bengio 口述神经网络简史
  • 新增对象时生成uuid传递到数据库_技术译文 | UUID 很火但性能不佳?今天我们细聊一聊...
  • CodeWarrior 使用教程第六课:定制
  • 【ML4CO论文精读】具有离散拆分送货和取货的车辆路径问题的禁忌搜索算法(Meng Qiu, 2018)
  • 《图数据库》——第 1 章 简介
  • 奥比中光深度相机使用笔记一
  • 奥比中光Femto相机环境配置
  • 奥比中光 ORBBEC Astra Mini Pro简单使用
  • 奥比中光 Astra pro 深度相机在ROS Melodic的调试
  • 在Ubuntu中获取奥比中光的深度值 Python代码
  • melodic 奥比中光(orbbec)相机安装
  • 奥比中光网络深度摄像头——人脸活体检测
  • linux使用ros打开奥比中光astra相机,查看红外图像
  • NVIDIA Jetson TX2 解决奥比中光 Astra pro相机的ros 打不开深度信息/camera/depth/image
  • 奥比中光进军世界的历程
  • 奥比中光-Astra相机如何用python实现输出RGB彩色图和Depth深度图,并输出三维坐标代码
  • 奥比中光 astra 乐视三合一体感摄像头采集深度图彩色图并保存
  • 奥比中光深度相机ros2 humble版安装分享
  • 奥比中光再度携手英伟达联合举办第三届3D视觉创新应用竞赛
  • Ubuntu 20.04下搭建奥比中光-Astra(详细教程)
  • 奥比中光astra 摄像头采集深度图和RGB图像(小白版)
  • Astra奥比中光相机驱动SDK,导库
  • 奥比中光(Deeyea)配置树莓派
  • 奥比中光相机的python采集代码
  • 奥比中光深度摄像头_奥比中光astra摄像头总结
  • 几种奥比中光SDK的功能说明以及使用方法
  • 全网最详细 Opencv + OpenNi + 奥比中光(Orbbec) Astra Pro /乐视三合一体感摄像头LeTMC-520 + linux 环境搭建

使用PostgreSQL以正确的顺序获取名称相关推荐

  1. 多媒体计算机技术19秋作业1,多媒体计算机技术19秋在线作业1 在数字音频信息获取与处理过程 下述正确的顺序是...

    多媒体计算机技术19秋在线作业1 在数字音频信息获取与处理过程 下述正确的顺序是 (11页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 14.9 积分 多 ...

  2. 计算机在播放音乐时 将数字音频信号转化为,计算机在数字音频信息获取与播放过程中正确的顺序是什么...

    计算机在数字音频信息获取与播放过程中正确的顺序是采样.A/D变换.压缩.存储.解压缩.D/A变换:其中把模拟音频转成数字音频,在电脑音乐里就称作采样,其过程所用到的主要硬件设备便是模拟/数字转换器. ...

  3. 下面是DHCP协议工作的4种消息,正确的顺序应该是(40)。【答案】B

    下面是DHCP协议工作的4种消息,正确的顺序应该是(40). ①DHCP Discovery ②DHCP Offer ③DHCP Request ④DHCP Ack (40)A.①③②④ B.①②③④ ...

  4. mybatis是什么_为什么SpringMVC可以正确解析方法参数名称,但MyBatis却不行?

    对Java字节码有一定了解的朋友应该知道,Java 在编译的时候,默认不会保留方法参数名,因此我们无法在运行时获取参数名称.但是在使用 SpringMVC 的时候,我发现一个奇怪的现象:当我们需要接收 ...

  5. 如何以正确的顺序重新安装驱动程序 | Dell 中国

    购买 支持 社区 我的帐户 购买 支持 社区 如何以正确的顺序重新安装驱动程序 在戴尔笔记本电脑或台式机上手动重新安装Microsoft Windows操作系统后,您还必须以正确的顺序重新安装戴尔设备 ...

  6. 正确解读PHP获取时间错误原因

    正确解读PHP获取时间错误原因 2009-12-09 14:25 佚名 百度博客 字号:T | T PHP获取时间错误是我们在开发运用PHP Date()函数时经常会遇到的问题.希望读者朋友通过本文介 ...

  7. c语言网络定向拉取数据,用C模拟了一个http请求,但是recv函数接收的数据不完整且欠安顺序获取信息...

    用C模拟了一个http请求,但是recv函数接收的数据不完整且不安顺序获取信息 用C模拟了一个http请求,但是recv函数接收的数据不完整且不安顺序获取信息 我把代码贴上 #include #inc ...

  8. Modifiers should be declared in the correct order 修饰符应按正确的顺序声明

    修饰符应按正确的顺序声明,这是由于修饰符顺序写反了. The Java Language Specification recommends listing modifiers in the follo ...

  9. 谈一谈a:link、a:visited、a:hover、a:active的正确使用顺序

    今天学到一个有趣的新知识呢,迫不及待的想分享一下.自学前端的这条路上,还在基础部分打转,未来好难,走好现在脚下的每一步才是我现在最重要的.小小地感慨一下,下面进入正题吧. 1. <a>标签 ...

最新文章

  1. RuntimeError: each element in list of batch should be of equal size
  2. Android java传递string类型数据给C
  3. P2048 [NOI2010]超级钢琴
  4. html正则表达式确认密码,如何使用正则表达式在流星中验证确认密码
  5. smartform连续打印,并自动补充空行
  6. Boost::context模块fiber的回声测试程序
  7. Swift 和 Objective-C 混编
  8. es6中的类及es5类的实现
  9. word里双横线怎么打_美人计 | 精致打工人秀智,教你内双怎么化
  10. 有用的正则表达式或JS方法
  11. 单例模式与线程安全问题浅析
  12. 谷歌发布机器学习云平台 开放语音识别API
  13. 一个黑客都要学习什么语言
  14. 01_LBP算法原理
  15. 事务实例--银行转账
  16. 雨滴桌面显示html,使用雨滴rainmeter打造炫酷桌面的方法!
  17. 计算机网口在哪看,联想电脑网线接口在哪
  18. Android解决getExternalStorageDirectory在29后废弃问题,亲测能用
  19. 2021年高压电工考试及高压电工考试资料
  20. Java ques: Unknown initial character set index ‘255‘ received from server. Initial client character

热门文章

  1. If you don't build your dreamer, someone will hire you to build theirs!
  2. java处理纳秒时间
  3. google翻译网页不错
  4. 3.17√ 识别次读入的一个以@为结束符的字符序列是否为形如”序列1序列2“模式的字符序列 ,序列12均没有,且序列2为序列1的逆序列
  5. 如何从0开始在鸿蒙OS中制作一个APP!
  6. 华硕飞行堡垒系列无线网经常显示“无法连接网络” || 一打开游戏就断网
  7. 做生产智能供料系统公司排名
  8. C++ 小鱼比可爱 题解
  9. c++中vector如何插入元素
  10. 使用Python实现量化交易机器人定时启动或停止小工具