Return default value
From PostgreSQL wiki
Jump to navigationJump to search return_default_value function
Works with PostgreSQL
Any version
Written in
plpgsql
Depends on
Nothing
Author: Emanuel
This function return the default value of a column:
CREATE FUNCTION ret_def(text,text,text) RETURNS text AS $$ SELECT columns.column_default::text FROM information_schema.columns where table_name = $2 and table_schema = $1 and column_name = $3 $$ LANGUAGE sql IMUTABLE;
Just call it at this way:
SELECT ret_def('schema','table','column');