473,385 Members | 1,478 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,385 software developers and data experts.

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 YourEmailAddressHere" to ma*******@postgresql.org)

Nov 22 '05 #1
3 11208
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_database()
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(integer)
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(integer)
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***@postgresql.org] Im Auftrag von sferriol
Gesendet: Dienstag, 24. Februar 2004 17:30
An: pg***********@postgresql.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 YourEmailAddressHere" to

ma*******@postgresql.org)
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.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***@postgresql.org] Im Auftrag von sferriol
Gesendet: Dienstag, 24. Februar 2004 17:30
An: pg***********@postgresql.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 YourEmailAddressHere" to

ma*******@postgresql.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
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...
4
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...
8
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...
3
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...
1
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...
0
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...
28
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...
0
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:...
9
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.