Proposal: is_castable - Mailing list pgsql-hackers

From Michał Wadas
Subject Proposal: is_castable
Date
Msg-id CAMEnU0Ae+h5zFoEra004NXTaPxPYABv4B9SdR9Tm15mNPT6OOQ@mail.gmail.com
Whole thread Raw
Responses Re: Proposal: is_castable  (Pavel Stehule <pavel.stehule@gmail.com>)
Re: Proposal: is_castable  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Currently there is no way to check if CAST will succeed.

Therefore I propose adding new function: is_castable

SELECT is_castable('foo' as time) // false
SELECT is_castable('123' as numeric) // true
SELECT is_castable(1.5 as int) // true
SELECT is_castable('1.5' as int) // false

Many users write their own functions:


Similar features are implemented in:
- SQL Server (as TRY_CONVERT)
- Oracle (as CONVERT([val] DEFAULT [expr] ON CONVERSION ERROR)

I would love to implement it myself, but my knowledge of C is superficial.

Thanks,
Michał Wadas

pgsql-hackers by date:

Previous
From: Kashif Zeeshan
Date:
Subject: Re: WIP/PoC for parallel backup
Next
From: Pavel Stehule
Date:
Subject: Re: Proposal: is_castable