Wednesday, 15 August 2012

Returning a single field from a postgresql function with an alias? -



Returning a single field from a postgresql function with an alias? -

how can homecoming single column postgresql function, alias column well?

the problem this: in documentation http://www.postgresql.org/docs/9.3/static/xfunc-sql.html has next example.

create function one() returns integer $$ select 1 result; $$ language sql;

this returns field named after function "one". wondering if there way name returned field else within function?

i tried using returns table construct, unusual thing happens this. if utilize single field, converted simple returns varchar, or whichever type used, 1 time deployed. not ideal things, such db backup/restore or bugfixes/modifications function.

does have ideas?

thanks in advance

it not possible specify alias of scalar homecoming value within function.

returns table does work, select * my_function(). e.g.:

create or replace function one() returns table(colname integer) $$ select 1 result; $$ language sql; select * one(); colname --------- 1 (1 row)

function postgresql return-type

No comments:

Post a Comment