Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
CREATE FUNCTION can_be_cast(i text, t regtype) RETURNS bool AS $$ BEGIN EXECUTE 'SELECT $1::' || t USING i; RETURN true; EXCEPTION WHEN OTHERS THEN RETURN false; END; $$ LANGUAGE plpgsql; SELECT can_be_cast('4', 'int'); SELECT can_be_cast('4foo', 'int'); -- false SELECT can_be_cast('2023-09-06', 'date'); SELECT can_be_cast('{"x": 5}', 'jsonb');

Stuck with a problem? Got Error? Ask AI support!

Copy Clear