472,952 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

[v7.0.3] loop through a database and union all tables begiining with "j" and name is like j### (#=digit)

how can i do that?

thx
peter
Jul 19 '05 #1
3 3844
You probably want to write a function (PL/PgSQL would be best) which
returns a row of a type matching the typical union row. If all the
tables are identical, you could just pick one and have the function
return a row of that type. If they are different, and you are selecting
just a subset of fields from each table, then you may need to create a
"dummy table" of the appropriate type.

This is what I did in a similar circumstance; I needed to loop through
all tables matching "draft_[0-9]{5}" (that is, draft_00000 through
draft_99999) and return each row). However, I also needed to "tack on"
an extra column in each row so I could tell what table it came from.
Rather than use the table name, I used the integer corresponding to the
table name's suffix.

create table "all_drafts" ("editor_id" INTEGER) inherits ("draft_template");

create or replace function fn_all_drafts() returns setof all_drafts
as
'declare
t record;
r all_drafts%ROWTYPE;
draft_curs REFCURSOR;
editor_id INTEGER;
begin
for t in select relname from pg_class where relname ~
''^draft_[0-9]{5}$'' loop
editor_id := substring(t.relname from ''[0-9]{5}$'') :: integer;
open draft_curs for execute ''select * from '' ||
quote_ident(t.relname);
loop
fetch draft_curs into r;
exit when not found;
r.editor_id := editor_id;
return next r;
end loop;
close draft_curs;
end loop;
return;
end;' language 'plpgsql';

--
Jeff Boes vox 269.226.9550 ext 24
Database Engineer fax 269.349.9076
Nexcerpt, Inc. http://www.nexcerpt.com
...Nexcerpt... Extend your Expertise
Jul 19 '05 #2
Jeff Boes <jb***@qtm.net> wrote in message news:<2d******************************@news.terane ws.com>...
You probably want to write a function (PL/PgSQL would be best)

thanks ... but ...

my server dosnīt support PL/PgSQL, only C, internal and SQL are avialable.

what should i do?

peter
Jul 19 '05 #3
ok - language creates - was simple! sorry for my stupid question ...

.... BUT :-)

this ist "my" function:

create function fn_all_jobcards() returns setof all_jobcards
as
'declare
t record;
r all_jobcards%ROWTYPE;
j_curs REFCURSOR;
editor_id INTEGER;
begin
for t in select relname from pg_class where relname ~
''^j_[0-9]{3}$'' loop
editor_id := substring(t.relname from ''[0-9]{3}$'') :: integer;
open j_curs for execute ''select * from '' ||
quote_ident(t.relname);
loop
fetch j_curs into r;
exit when not found;
r.editor_id := editor_id;
return next r;
end loop;
close j_curs;
end loop;
return;
end;' language 'plpgsql';

creatation is successful ...

but it returns:
# select fn_all_jobcards();

NOTICE: plpgsql: ERROR during compile of fn_all_jobcards near line 4
ERROR: parse error at or near "REFCURSOR"

whats wrong? plz help me!

greets
peter
Jul 19 '05 #4

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

Similar topics

23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
27
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a...
4
by: dmiller23462 | last post by:
Somebody take a look and give me any suggestions? My brain is nuked... Here's my deal....I have online submission forms on my intranet at work here....I am appending to an Access DB with the...
2
by: MLH | last post by:
I used the following SQL to create a new table in a database on a remote MySQL server by copying one already there. I know the table exists SOMEWHERE in cyberspace. I can read its data, write to...
1
by: Richard Holliingsworth | last post by:
Hello: The group has new 'standards' for online forms and I need to change the 'style' of my existing forms (A2002). Can I do this? I can't find a way using the GUI or the properties. ...
4
by: mosscliffe | last post by:
I have been messing with the above all afternoon. I must just be thick I am using an AccessDataSource I have tried modifying the select but I can not find the right syntax to concatenate...
5
by: MLH | last post by:
I have an Access 2.0 app I still use. How best can I list all tables in a combo- box on an Access 2.0 form - just tables beginning with "ABCDE"? Bear in mind that I'm adding new tables to the app...
2
by: Arvin Portlock | last post by:
My SQL experience is pretty limited, sorry if this is a REALLY basic question. I have a database of bibliographic records. Each record is of a certain type as recorded in a Type field: books,...
3
by: Manish Sawjiani | last post by:
Dear experts i have just migrated from asp to asp.net and i am missing the loop for creating tables. while in asp one could just start a loop anywhere withing <% %is this out of style in the...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.