当前位置:网站首页>PG SQL intercepts the string to the specified character position
PG SQL intercepts the string to the specified character position
2022-04-23 13:42:00 【Ruo Xiaoyu】
I'm doing it today PG Data to HIVE Data exchange tasks for , Because a field is PG Medium is Varchar type ,hive yes bigint, And it happened PG The stored values of this field in are added with decimal places , Cause field type conversion failure .

Now you need to cut off the part after the decimal point in the string .
At first, I tried to use CHARINDEX To get the position of the decimal point , And then use substring The function intercepts the value before the position .
select CAST(SUBSTRING(sal_qty, 1 , CHARINDEX('.',sal_qty)-1)as bigint)
But the runtime found that PG There is no CHARINDEX function .
SQL error [42883]: ERROR: function charindex(unknown, character varying) does not exist
Suggest :No function matches the given name and argument types. You might need to add explicit type casts.
Find the corresponding replacement function in the official documentation
https://www.postgresql.org/docs/current/functions-string.html
Find one position function 
position ( substring text IN string text ) → integer
Returns first starting index of the specified substring within string, or zero if it's not present.
position('om' in 'Thomas') → 3
Test it
select sal_qty, cast(SUBSTRING(sal_qty, 1 , position ('.' in sal_qty) - 1) as bigint) as sal_qty_int from table_test
Return results , In line with expectations .

In addition, you can try to use strpos function , Function and position identical , But pay attention to the parameter position

strpos ( string text, substring text ) → integer
Returns first starting index of the specified substring within string, or zero if it's not present. (Same as position(substring in string), but note the reversed argument order.)
strpos('high', 'ig') → 2
select sal_qty, cast(SUBSTRING(sal_qty, 1 , strpos(sal_qty,'.')-1)as bigint) as sal_qty_int from table_test
版权声明
本文为[Ruo Xiaoyu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230602186539.html
边栏推荐
- Window function row commonly used for fusion and de duplication_ number
- GDB的使用
- SAP ui5 application development tutorial 72 - animation effect setting of SAP ui5 page routing
- sys. dbms_ scheduler. create_ Job creates scheduled tasks (more powerful and rich functions)
- TCP reset Gongji principle and actual combat reproduction
- playwright控制本地穀歌瀏覽打開,並下載文件
- Detailed explanation of ADB shell top command
- Playwright controls local Google browsing to open and download files
- Solve the problem of Oracle Chinese garbled code
- Uninstall MySQL database
猜你喜欢

Summary of request and response and their ServletContext
![[indicators] precision, recall](/img/40/8fbd9b83bd2fe8ac13ffeb1834b002.png)
[indicators] precision, recall

Window analysis function last_ VALUE,FIRST_ VALUE,lag,lead
![[Video] Bayesian inference in linear regression and R language prediction of workers' wage data | data sharing](/img/12/a330b5e77921bbfa8e96fcbc660daa.png)
[Video] Bayesian inference in linear regression and R language prediction of workers' wage data | data sharing

面试官给我挖坑:单台服务器并发TCP连接数到底可以有多少 ?

Usereducer basic usage

【重心坐标插值、透视矫正插值】原理以及用法见解
![[point cloud series] foldingnet: point cloud auto encoder via deep grid deformation](/img/c0/cc29ae6948dbe42954cd9da326ef77.png)
[point cloud series] foldingnet: point cloud auto encoder via deep grid deformation

Stack protector under armcc / GCC

联想拯救者Y9000X 2020
随机推荐
playwright控制本地穀歌瀏覽打開,並下載文件
Campus takeout system - "nongzhibang" wechat native cloud development applet
Generate 32-bit UUID in Oracle
Lenovo Savior y9000x 2020
Interface idempotency problem
Example of specific method for TIA to trigger interrupt ob40 based on high-speed counter to realize fixed-point machining action
Tersus notes employee information 516 MySQL query (time period uniqueness judgment of 2 fields)
Exemple de méthode de réalisation de l'action d'usinage à point fixe basée sur l'interruption de déclenchement du compteur à grande vitesse ob40 pendant le voyage de tia Expo
100000 college students have become ape powder. What are you waiting for?
Oracle index status query and index reconstruction
[point cloud series] relationship based point cloud completion
Machine learning -- model optimization
Django::Did you install mysqlclient?
切线空间(tangent space)
Oracle modify default temporary tablespace
SAP UI5 应用开发教程之七十二 - SAP UI5 页面路由的动画效果设置试读版
What does the SQL name mean
Double pointer instrument panel reading (I)
Super 40W bonus pool waiting for you to fight! The second "Changsha bank Cup" Tencent yunqi innovation competition is hot!
Opening: identification of double pointer instrument panel