![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Now I want to create a function where I can pass the "table_id" and it create a structure with a variable number of columns resulting from the table "Table_fields. For example "f_crosstab_value(table_id)": table_value_id| code_name | table_name | colour | heavy | shape | ... 1 | potatoes | vegetables| 5 | 100 | sphere | ... 2 | insalata | vegetables| | 50 | various | ... The values are an example. Is without saying that every "table_name" will have different product names and properties (fields) with different specifications. For those codes that have no value, since the structure of table will equal for all records, I will leave the field blank or null. The structure also allows you to add new properties without affecting the physical table. Someone can help me to write this function? |
#3
| |||
| |||
|
|
Check out the the tablefunc contrib module, it contains a function that might do what you want (crosstab) http://www.postgresql.org/docs/curre...tablefunc.html |
#4
| |||
| |||
|
|
Someone can help me to write this function? |
#5
| |||
| |||
|
|
Someone can help me to write this function? Where do you have a problem? With writing a table function in general? Or do you hang at a certain step? |
#6
| |||
| |||
|
|
It is possible to define a function as ... RETURNS SETOF RECORD but then you have to supply the signature when you call the function: SELECT func(args) AS (col1 type1, col2 type2, ...) That will probably make a generic function less useful that you intend. |
![]() |
| Thread Tools | |
| Display Modes | |
| |