How to implent CONVERT ( data_type [ ( length ) ] , expression ) function in postgreSQL

From: rohtodeveloper <rohtodeveloper(at)outlook(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: How to implent CONVERT ( data_type [ ( length ) ] , expression ) function in postgreSQL
Date: 2014-11-02 10:10:14
Message-ID: BAY178-W4767B9DD46338D3880A0BFC4980@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dear

In SQLServer, there'are two functions to converte an expression of one data type to another.
1. CAST ( expression AS data_type [ ( length ) ] )2. CONVERT ( data_type [ ( length ) ] , expression )
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.
1. CREATE FUNCTION ..... The function's arguments can only be expressions but not data_type . 2. Modifying the gram.y .....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.
I wonder whether there's a better way to solve this problem. Any help will be appreciated.
Best RegardsRohtodeveloper

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Atri Sharma 2014-11-02 10:30:14 Re: How to implent CONVERT ( data_type [ ( length ) ] , expression ) function in postgreSQL
Previous Message Marko Tiikkaja 2014-11-02 04:10:25 Silly coding in pgcrypto