How to implent CONVERT ( data_type [ ( length ) ] , expression ) function in postgreSQL - Mailing list pgsql-hackers

From rohtodeveloper
Subject How to implent CONVERT ( data_type [ ( length ) ] , expression ) function in postgreSQL
Date
Msg-id BAY178-W4767B9DD46338D3880A0BFC4980@phx.gbl
Whole thread Raw
Responses Re: How to implent CONVERT ( data_type [ ( length ) ] , expression ) function in postgreSQL  (Atri Sharma <atri.jiit@gmail.com>)
List pgsql-hackers
<div dir="ltr"><div style="line-height: 21px; color: rgb(68, 68, 68); font-family: 'Microsoft YaHei UI', 'Microsoft
YaHei',宋体, Calibri, sans-serif; font-size: 15px; background-color: rgb(255, 255, 255);">Dear</div><div
style="line-height:21px; color: rgb(68, 68, 68); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', 宋体, Calibri,
sans-serif;font-size: 15px; background-color: rgb(255, 255, 255);"><br /></div><div style="line-height: 21px; color:
rgb(68,68, 68); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', 宋体, Calibri, sans-serif; font-size: 15px;
background-color:rgb(255, 255, 255);"><br /></div><div style="line-height: 21px; color: rgb(68, 68, 68); font-family:
'MicrosoftYaHei UI', 'Microsoft YaHei', 宋体, Calibri, sans-serif; font-size: 15px; background-color: rgb(255, 255,
255);">InSQLServer, there'are two functions to converte an expression of one data type to another.</div><div
style="line-height:21px; color: rgb(68, 68, 68); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', 宋体, Calibri,
sans-serif;font-size: 15px; background-color: rgb(255, 255, 255);"><br /></div><div style="line-height: 21px; color:
rgb(68,68, 68); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', 宋体, Calibri, sans-serif; font-size: 15px;
background-color:rgb(255, 255, 255);">1. CAST ( expression AS data_type [ ( length ) ] )</div><div style="line-height:
21px;color: rgb(68, 68, 68); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', 宋体, Calibri, sans-serif; font-size:
15px;background-color: rgb(255, 255, 255);">2. CONVERT ( data_type [ ( length ) ] , expression )</div><div
style="line-height:21px; color: rgb(68, 68, 68); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', 宋体, Calibri,
sans-serif;font-size: 15px; background-color: rgb(255, 255, 255);"><br /></div><div style="line-height: 21px; color:
rgb(68,68, 68); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', 宋体, Calibri, sans-serif; font-size: 15px;
background-color:rgb(255, 255, 255);">However, In PostgreSQL, there's only the CAST ( expression AS data_type [ (
length) ] ) function. I have tried the following two ways to implenting the CONVERT ( data_type [ ( length ) ] ,
expression) function, but both are failed.</div><div style="line-height: 21px; color: rgb(68, 68, 68); font-family:
'MicrosoftYaHei UI', 'Microsoft YaHei', 宋体, Calibri, sans-serif; font-size: 15px; background-color: rgb(255, 255,
255);"><br/></div><div style="line-height: 21px; color: rgb(68, 68, 68); font-family: 'Microsoft YaHei UI', 'Microsoft
YaHei',宋体, Calibri, sans-serif; font-size: 15px; background-color: rgb(255, 255, 255);">1. CREATE FUNCTION
..... </div><divstyle="line-height: 21px; color: rgb(68, 68, 68); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei',
宋体,Calibri, sans-serif; font-size: 15px; background-color: rgb(255, 255, 255);">The function's arguments can only be
expressionsbut not data_type . </div><div style="line-height: 21px; color: rgb(68, 68, 68); font-family: 'Microsoft
YaHeiUI', 'Microsoft YaHei', 宋体, Calibri, sans-serif; font-size: 15px; background-color: rgb(255, 255, 255);">2.
Modifyingthe gram.y .....</div><div style="line-height: 21px; color: rgb(68, 68, 68); font-family: 'Microsoft YaHei
UI','Microsoft YaHei', 宋体, Calibri, sans-serif; font-size: 15px; background-color: rgb(255, 255, 255);">The CONVERT (
data_type[ ( length ) ] , expression ) is in grammer conflict with the PostgreSQL self's
convert(data,src_encoding_name,dest_encoding_name)function. And the PostgreSQL self's
convert(data,src_encoding_name,dest_encoding_name)function cannot be used.</div><div style="line-height: 21px; color:
rgb(68,68, 68); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', 宋体, Calibri, sans-serif; font-size: 15px;
background-color:rgb(255, 255, 255);"><br /></div><div style="line-height: 21px; color: rgb(68, 68, 68); font-family:
'MicrosoftYaHei UI', 'Microsoft YaHei', 宋体, Calibri, sans-serif; font-size: 15px; background-color: rgb(255, 255,
255);">Iwonder whether there's a better way to solve this problem. </div><div style="line-height: 21px; color: rgb(68,
68,68); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', 宋体, Calibri, sans-serif; font-size: 15px;
background-color:rgb(255, 255, 255);">Any help will be appreciated.</div><div style="line-height: 21px; color: rgb(68,
68,68); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', 宋体, Calibri, sans-serif; font-size: 15px;
background-color:rgb(255, 255, 255);"><br /></div><div style="line-height: 21px; color: rgb(68, 68, 68); font-family:
'MicrosoftYaHei UI', 'Microsoft YaHei', 宋体, Calibri, sans-serif; font-size: 15px; background-color: rgb(255, 255,
255);">BestRegards</div><div style="line-height: 21px; color: rgb(68, 68, 68); font-family: 'Microsoft YaHei UI',
'MicrosoftYaHei', 宋体, Calibri, sans-serif; font-size: 15px; background-color: rgb(255, 255,
255);">Rohtodeveloper</div></div>

pgsql-hackers by date:

Previous
From: Marko Tiikkaja
Date:
Subject: Silly coding in pgcrypto
Next
From: Atri Sharma
Date:
Subject: Re: How to implent CONVERT ( data_type [ ( length ) ] , expression ) function in postgreSQL