473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

postgre function

Hi,

I have a problem regarding on making function in postgre.

I am newbie for this.

My problem is that i want to make a function in postgre that accepts the name of the table. In the processed of the function, the table name inputted should be merge to the another table. And, the result values of query returned.


Any idea for this.

Kindly show the code also. And, if you know any referrence material for the procedural language such as the reserved words or keywords in postgresql, or any sample code, pls, put it the link also. thanks.

Please help.

I highly appreciate for your help. :)
May 7 '09 #1
4 3902
rski
700 Expert 512MB
Looks simple but what do you mean
In the processed of the function, the table name inputted should be merge to the another table.
What is another table?

And, the result values of query returned.
You mean the concatenation should be outputted?

The best manual is at postgresql.org
May 7 '09 #2
hi,

thanks for the reply..

Ok, i'll explain clearly of what i want to say. My problem is to make a function in Postgre that function is to accepts a parameter which the name of the table.
The process of this function is read the table name that passed and make a query of that table joining with another table that is already defined in this function. This function would return the rows result of this query.

example:

function : my_function(pas_table)
body :
/* make some processed */

Select * from pass_table inner join another_table using(id)
return query results;
end:

This function should return the results of the query from a joined tables.

May ask what type of return shoud i used for this?

I am newbie for this sql programming.
sorry, if i can't explain well.

Pls, help me.:)
May 8 '09 #3
Help me for this pls......

I'm trying to search what kind of return type in sql that would return the query results in joined table.

CREATE OR REPLACE FUNCTION "public"."view_table" (table_1 text) RETURNS SETOF "public"."table_2" AS
$body$
DECLARE
r table_2%rowtype;
BEGIN
FOR r IN SELECT * FROM table_2 LOOP
RETURN NEXT r;
END LOOP;
END
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100 ROWS 1000;
Select * from view_table('table1'')
This is a sample code but this would only return a rows for table_2. I am not finished to implement it. I want to join the table_1 and table_2 and would return their query results. But i don't know yet what is the return type to use for these two query.
Additionaly, I also don't know how to cancatenate the value from parameter which the table_1 to the Select statement in order to make a sql statement such as
Select * from table_1 inner join table_2 using(thier_id)
Kindly, help me for this....

I appreaciate a lot for any help, suggestion, idea and comment.

Thanks :)
May 9 '09 #4
rski
700 Expert 512MB
You should use 'setof record' as the return type.

To do a dynamic select statement use EXECUTE statement
Expand|Select|Wrap|Line Numbers
  1. for r in EXECUTE 'Select * from '||table_1||' inner join table_2 using(thier_id)' 
  2.  
but r should be a record type.

You'll see that working with records isn't simple, so it is worth to do such a function? Do you really need that function, maybe there is a better, simpler solution.
May 9 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jason Tesser | last post by:
I am looking into using PostgreSQL on the backend here. I work for a Bible College. We are putting together a new software package. The database would be on a LInux box but our domain is M$ so we...
0
by: COXJ94 | last post by:
I have these postgre dbs, and I know nothing about them. I do know that I need to migrate them to db2. I've done someresearch and I think pg_dump with extract the ddls from postgre much like...
4
by: Brandon | last post by:
Is there a call redirector available that redirects the calls to the PHP MySql API (mysql_connect etc.) to a Postgre database? This would be very usefull since a lot of PHP Scripts are coded for...
1
by: Pradeep83 | last post by:
Hi Everybody Can anybody help me where i can open source for postgre sql that is compatiable for Soalris 10 OS.and how to install the same after downloading , As I am new to this Database...
14
Sakalicek
by: Sakalicek | last post by:
Hi all, could you please help me with my big problem? I have WebService on IIS. This WebService has methods to control database stored on server. I am using Postgre database and to access to...
4
by: =?iso-8859-1?B?RulybmFz?= | last post by:
Hello all, I'm starting a new project and my boss asked me about "C# + Postgre"... I told him that i will look for some information.. Is there something that I should know, like some bug or...
1
by: nilart | last post by:
Hi, I have an installer application (Installshield) which installs postgre DB programmatically on windows: I have a requirement where postgre DB is expected work after upgrading OS from windows XP...
0
by: Miraj Godha | last post by:
Hi , I want to send array from java program to postgre. For oracle we can achieve it by using: ArrayDescriptor desc = ArrayDescriptor.createDescriptor("TYPE", conn); ARRAY newArray = new...
2
by: dvelst | last post by:
Hi All, I have the following query which was based on a working query in MySQL: (don't be afraid of the size of the query you see below, later on I will concentrate on part of this query) ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.