Tuesday 15 March 2011

Postgresql function creating ERROR: return type mismatch in function declared to return name -



Postgresql function creating ERROR: return type mismatch in function declared to return name -

almost burning out writing post lastly resort...

hi all, looking help first function need create. read understand need add together function header , footer set of sql commands create function.

i have view have created works fine... here code it

create view invoice_v select customer.firstname, lastname, customer_addresses.address, orders.order_id, order_date, order_total, order_details.product_id, quantity, unitprice, product.product_name customer, customer_addresses, orders, order_details, product customer.customer_id = customer_addresses.customer_id , customer.customer_id = orders.customer_id , orders.order_id = order_details.order_id , product.product_id = order_details.product_id; select firstname, lastname, address, order_id, order_date, product_id, product_name, quantity, unitprice, order_total invoice_v order_id = 02;

what create view invoice details order_id 2.

i need similar thing function. im not sure how done.

this tried do... failed, im sorry if seems extremely stupid, i'm new this...

create function invoiceforprint() returns name ' select customer.firstname, lastname, customer_addresses.address, orders.order_id, order_date, order_total, order_details.product_id, quantity, unitprice, product.product_name customer, customer_addresses, orders, order_details, product customer.customer_id = customer_addresses.customer_id , customer.customer_id = orders.customer_id , orders.order_id = order_details.order_id , product.product_id = order_details.product_id; ' language sql;

the code above gives me error

error: homecoming type mismatch in function declared homecoming name detail: final statement must homecoming 1 column. context: sql function "invoiceforprint"

i don't know parameter supposed utilize return. help on matter, much appreciated.

sorry not near postgres db untested.

what after called table function, there illustration here http://www.postgresql.org/docs/9.1/static/sql-createfunction.html

create function invoiceforprint() returns table(firstname text , lastname text , address text , order_id int , order_date date , order_total numeric , product_id int , quantity numeric , unitprice numeric, , product_name text ) $$ select customer.firstname , lastname , customer_addresses.address , orders.order_id , order_date , order_total , order_details.product_id , quantity , unitprice , product.product_name customer, customer_addresses, orders, order_details, product customer.customer_id = customer_addresses.customer_id , customer.customer_id = orders.customer_id , orders.order_id = order_details.order_id , product.product_id = order_details.product_id; $$ language sql;

function postgresql

No comments:

Post a Comment