sql - How to pass a record as parameter for PL/pgSQL function? -


i keep looking answer online cannot find it.

i trying pass 1 record on pl/pgsql function. tried in 2 ways.

fist way :

create or replace function translatetoreadabledate(mrecord dim_date%rowtype) returns void $$ 

that ouput :

psql:requestexample.sql:21: error:  syntax error @ or near "%" line 1: ... function translatetoreadabledate(mrecord dim_date%rowtype) ...                                                              ^ 

second way :

create or replace function translatetoreadabledate(mrecord record) returns void $$ 

and there output

psql:requestexample.sql:21: error:  pl/pgsql functions cannot accept type record 

someone know how please ?

create or replace function translatetoreadabledate(mrecord dim_date) returns void $$      begin      select dim_day.name || ' (' || dim_day_in_month.id || ') ' || dim_month.name   || 'is ' || dim_week.id || ' week of year. ' "une phrase", dim_quarter.id, dim_year.id     dim_date dd      join dim_day on dd.day_id = dim_day.day_id      join dim_day_in_month on dd.day_in_month_id = day_in_month.day_in_month_id      join dim_week on dd.week_id = dim_week.week_id      join dim_month on dd.month_id = dim_month.month_id      join dim_quarter on dd.quarter_id = dim_quarter.quarter_id      join dim_year on dd.year_id = dim_year.year_id     dd.day_id = mrecord.day_id      , dd.day_in_month_id = mrecord.day_in_month_id      , dd.week_id = mrecord.week_id      , dd.month_id = mrecord.month_id      , dd.quarter_id = mrecord.quarter_id      , dd.year_id = mrecord.year_id;      end;     $$ language plpgsql; 

try this:

create or replace function translatetoreadabledate(mrecord dim_date) returns void $$ 

dim_date must table.

edit:

ok, i'm really confused.

  1. a date should column, not table. can't understand why create table date values.
  2. you can format dates no problem to_char. read this: data type formatting functions learn how to. function created makes 0 sense.
  3. are outputting pl/pgsql? shouldn't formatting done middle tier? should return date database.

lastly, recommend reading pl/pgsql manual. there's lots of stuff in there.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -