473,772 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selection in pgsql using dynamic tables.

1 New Member
Hi,
I have a function(stored procedure) in the database. I need to pass the table name which is a variable. How do i do that?
Example :
I have 1st table : table name - cities
location | city
(text) | (text)
---------------------
1 bangalore
2 mangalore

Now from this table depending upon location 1 or 2, I need to select the particular city and each city is another table for me which contains different parameters like, population, num of educated ppl, and num of schools.
So, from this selected city, I need to select data from population column.

This needs to be done in stored procedures in pgsql and so, I would need a single query for this. If any one knows, please help me out.
Nov 23 '07 #1
1 4171
rski
700 Recognized Expert Contributor
Hi,
I have a function(stored procedure) in the database. I need to pass the table name which is a variable. How do i do that?
Example :
I have 1st table : table name - cities
location | city
(text) | (text)
---------------------
1 bangalore
2 mangalore

Now from this table depending upon location 1 or 2, I need to select the particular city and each city is another table for me which contains different parameters like, population, num of educated ppl, and num of schools.
So, from this selected city, I need to select data from population column.

This needs to be done in stored procedures in pgsql and so, I would need a single query for this. If any one knows, please help me out.
My english isn't good but aren't you looking for a dynamic queries in plpgsql (execute command see here
http://www.postgresql.org/docs/curre...-EXECUTING-DYN
Nov 23 '07 #2

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

Similar topics

9
2720
by: Google Mike | last post by:
To my surprise last month, my dad wanted to start dabbling in PHP and MySQL or pgSQL. I've been helping him out a bit. He's into athletic medicine and wants to have a website to help athletes and physical therapists improve performance. His current web hosting provider -- Earthlink -- doesn't give him anything but PHP 3.0.x. I want to get him at least on PHP 4.2.x (or better) along with either MySQL or PostgreSQL (pgSQL) support. I've...
3
4726
by: hamvil79 | last post by:
I'm implementig a java web application using MySQL as database. The main function of the application is basically to redistribuite documents. Those documents (PDF, DOC with an average size around 2Mb) are stored in BLOB column. The amount of documents for the first year should not exceed 5/6 Giga, but I cannot make prevision for the next years. Those documents are mainly just accessed (update and delete are not so
34
5071
by: Karam Chand | last post by:
Hello I have been working with Access and MySQL for pretty long time. Very simple and able to perform their jobs. I dont need to start a flame anymore :) I have to work with PGSQL for my companies current project. I have been able to setup postgresql in my rh box and
2
1632
by: Gellert, Andre | last post by:
Hello, I have following problem: A user "xy" shouldn't have any rights to a table, but needs data from the content of the table. My idea was to setup a PL/PGSQL procedure to fetch the data from the table, so that the user only is allowed to access the procedure. I also tried using a SQL function, but this doesn't work, too. Working with views may be a solution - or are e.g. cursors
1
2093
by: Graeme Hinchliffe | last post by:
Hiya, Not had much experience with tiggers under postgres but am liking them so far. My problem is this. I am writing an updates system, postgres holds the master copy of the database, any changes made to this are logged in an updates table which is monitored by a daemon, which if any updates are spotted propigates them to the remote servers. I have written an initial trigger that spots any changes made to the
2
1800
by: Tim Vadnais | last post by:
Hi, My boss wants to add some logging functionality to some of our tables on update/delete/insert. I need to log who, when, table_name, field name, original value and new value for each record, but only logging modified fields, and he wants me to do this wing postgres pgSQL triggers. We are given 10 automatically created variables. Some of which I know I can use: NEW, OLD, TG_WHEN, TG_OP and TG_RELNAME. I can use these to get...
2
4965
by: Matt | last post by:
Hi, I'm sure this has been asked before, but my searches haven't come up with an example. I'm writing a generic trigger function called from different tables in plpgsql that needs to get the value of the primary key column from OLD. I can find out the pkey column name by querying the system tables, but the only way I've found of getting the value of that column is by
5
4576
by: srampally | last post by:
I need the capabilty to hide/show a selection list, just the way its done at http://www.lufthansa.com (place the cursor over "Group Companies"). However, I am looking for a javascript that is much simpler. Here is what I have until now. Problems with my code: 1. The selection list becomes invisible when I try to select an option (in Firefox). 2. The selection list stays visible when I just place the cursor over selection list and move...
4
4542
by: pravinasp | last post by:
Hello there I have been trying to generate a dynamic querystring thats to be executed inside a trigger function and every time I use NEW.* pl/pgsql throws an error saying 'column * does not exist'. CREATE OR REPLACE FUNCTION matrix_test_insert_trigger() RETURNS trigger AS $$ BEGIN
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10039
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.