473,883 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic views

hello
is it possible with postgres 7.2 or more, to define a dynamic view.
For example, i have a table with a column 'user'
and i want to define a view which gives infomrations from different
tables but the user has to specifie the 'user' parameter when using a
select to the view

sylvain
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 22 '05 #1
3 11234
On Tuesday 24 February 2004 16:29, sferriol wrote:
hello
is it possible with postgres 7.2 or more, to define a dynamic view.
For example, i have a table with a column 'user'
and i want to define a view which gives infomrations from different
tables but the user has to specifie the 'user' parameter when using a
select to the view


You can have a view something like:

SELECT * FROM personal_info WHERE owner = CURRENT_USER;

There are some other vars/functions too SESSION_USER and current_databas e()
etc.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 22 '05 #2
Hi sylvain,

i think what you need is a so-called "set-returning-function":

if you just need sql (example with a table called user_data):

create or replace function user_info(integ er)
returns setof user_data as '
select * from user_data where user_id = $1;
' language 'sql';

if you need plpgsql:

create or replace function user_info(integ er)
returns setof user_data as '
declare
p_user_id alias for $1;
v_row record;
begin
for v_row in select * from user_data where user_id = p_user_id
loop
-- business logic here, eg. Some if-statements or
sub-queries
-- write a row to the result set
return next v_row;
end loop;

return;

' language 'plpgsql';

if you want to return rows that do not come from one single table you
will probably need to create a type:

create type user_data as (
user_id integer,
username varchar
);

you can then use that type in the "returns setof TYPE" clause of the
function.

Hope that helps. You should search for info about set-returning
functions for more details.
-----Ursprüngliche Nachricht-----
Von: pg************* ****@postgresql .org [mailto:pgsql-general-
ow***@postgres ql.org] Im Auftrag von sferriol
Gesendet: Dienstag, 24. Februar 2004 17:30
An: pg***********@p ostgresql.org
Betreff: [GENERAL] dynamic views

hello
is it possible with postgres 7.2 or more, to define a dynamic view.
For example, i have a table with a column 'user'
and i want to define a view which gives infomrations from different
tables but the user has to specifie the 'user' parameter when using a
select to the view

sylvain
---------------------------(end of broadcast)---------------------------TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to

ma*******@postg resql.org)
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 22 '05 #3
Sorry i forgot to mention:

-that you need pg 7.3 for the set-returning function feature.

-how to select from the function:

select * from _YOUR_FUNCTION( PARAMETER);

and NOT:

select _YOUR_FUNCTION( PARAMETER);
-----Ursprüngliche Nachricht-----
Von: pg************* ****@postgresql .org [mailto:pgsql-general-
ow***@postgres ql.org] Im Auftrag von sferriol
Gesendet: Dienstag, 24. Februar 2004 17:30
An: pg***********@p ostgresql.org
Betreff: [GENERAL] dynamic views

hello
is it possible with postgres 7.2 or more, to define a dynamic view.
For example, i have a table with a column 'user'
and i want to define a view which gives infomrations from different
tables but the user has to specifie the 'user' parameter when using a
select to the view

sylvain
---------------------------(end of broadcast)---------------------------TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to

ma*******@postg resql.org)
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
7943
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the header of the datagrid in the "ItemDataBound" method of the grid. However, once, they are added in the grid, i seem to lose the event handler for the same control. Is there anyone who has tried this before and knows why this is hapenning ??
4
8107
by: MD | last post by:
I am trying to create a dynamic SQL statement to create a view. I have a stored procedure, which based on the parameters passed calls different stored procedures. Each of this sub stored procedure creates a string of custom SQL statement and returns this string back to the main stored procedure. This SQL statements work fine on there own. The SQL returned from the sub stored procedure are returned fine. The datatype of the variable that...
8
5283
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is developing a web-based application, one part of which involves allowing the user the ability to page through transaction "history" information. The _summary_ history table will have the following fields: ServiceName, Date, User-Ref1, User-Ref2,...
3
10197
by: KemperR | last post by:
Hello Experts outhere, may be someone can tell me whats going wrong with my ADOX trial. I have an Access 2002 database with some tables and queries (views) The code listed below works well up to the point where I want to add the new view to the views collection. I get Runtime error 3001 which is telling me "Arguments are of wrong type,are out of acceptable range or conflict with one another"
1
2165
by: Jesper Odgaard | last post by:
Hi, I'm migrating a program to C# that I wrote using MFC. The programs GUI was split vertically in two halfs with a tree control to the left. Accordingly to the different items that could be selected in this tree view, the right side of the GUI showed different Formviews that was replaced dynamically at runtime. I would like to do the same thing in my C# version of the program. However I cant figure out which controls could
0
369
by: Jesper DK | last post by:
Hi, I'm writing a windows explorer like application. The GUI is divided by a vertical splitter. To the left I have a tree control. To the right of the splitter I would like to display one of several different user controls according to what is selected in the tree control. Now, I can do this by placing all of my different user controls on the form and then use .Show() and .Hide() on the controls. However, I do not fancy this technique,...
28
72634
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and 2005 Test Environments. What is the purpose of a view if I can just copy the vode from a view and put it into a stored procedure? Should I be accessing views from stored procedures?
0
1815
by: eric.olstad | last post by:
I want to create a web site that can dynamically creates tabs -- like firefox functionality built into a web site. Take a look at this site to get an idea of what I'm looking to do: http://www.krugle.com/demos/Overview5_800.html Now, I'm not looking to copy the entire interface from Krugle, but I am very interested to understand how they are implementing those tabbed panes. It's pretty brilliant because they're dynamic.
9
2991
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I got the core of the javascript from here: http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm I noticed in the demo that sometimes the content takes a long
0
9796
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
11153
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
10757
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
10860
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
10420
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
6002
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4620
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3239
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.