sql - Column aliases from a function in PostgreSQL -
i've started using postgresql (i've history mssql , mysql) , have question aliases. if have following sql declared in function:
return query select "table"."col1" "column 1", "table"."col2" "column 2" "table";
highlighting , running alone gives me expect:
column 1 | column 2 ------------------------ contents | contents of | of col1 | col2
however calling function outside seems ignore aliases set:
select * "f_function"();
gets:
col1 | col2 ------------------------ contents | contents of | of col2 | col2
i tried changing return type definition of function in case of higher naming priority parent process:
... returns table (col1 integer "column 1", col2 integer "column 2") ...
but syntactically wrong.
as said i've started using postgresql might missing obvious, can't seem find specific situation.
to clear, i'm wanting able call function , have column aliases appear in returned table.
any ideas?
edit: solution yuri levinsky
... returns table ("column 1" integer, "column 2" integer) ...
with
return query select "table"."col1", "table"."col2" "table";
returns table:
column 1 | column 2 ------------------------ contents | contents of | of col1 | col2
please use following example: returns table (dstring character varying, ...) select * function_name;
you see column names dstring,... specified in function declaration. don't need use alias: name wish.
Comments
Post a Comment