Thread: Triggers to create Tables

Triggers to create Tables

From
Martin Möderndorfer
Date:
hi,

this is the part II of a question i already asked:

i have some tables:
create table css_class(nr int4, classname varchar(50));
create table css_prop(nr int4, name varchar(50), val varchar(50),
classnr int4);
(css_prop.classnr foreign key-> css_class.nr)

i would need a trigger on update and insert who takes all entries from
the tables above and put them into a textfile in the following stype

.n-th_of_css_class {
    n-th_of_css_prop.name(*) : n-th_of_css_prop.val(*);
    n+1-th_of_css_prop.name(*): [...]
}
.n+1-th_of_css_class { [...]

with other words: i want to create a cascading style sheet out of the
table:
css files look something like that

.cassname {
    property1 : value_prop1;
    property2 : value_prop2;
    [...]
}
[...]

Can anyone help?
a c-function would be ok too (_really_ think that i need one) but the
file has to be created by the database itself.

Idea for the future: whole html pages built out of the databased
resulted by trigger/query combination. (not the question _yet_)

MArtin

...

From
Eric Lee Green
Date:
I am curious about the cost of triggers.

The MySQL guys claim that they are very expensive. But if I want to put a
trigger on an "update" for a table so that if changing a "N" to a "Y" in a
status variable it'll go update another table, e.g. sort of a foreign key
constraint since PostGreSQL doesn't have one, what kind of cost is this
for normal operations on that table? (Oh, it will update one single record
in that other table, and the key value has a unique index on it, so that
should not be a problem).

--
Eric Lee Green         eric@linux-hw.com     http://www.linux-hw.com/~eric
     Beware of those who would sell you a 7200RPM Quantum as an
    Enterprise-class hard drive.


Re: [SQL] Triggers to create Tables

From
tolik@icomm.ru (Anatoly K. Lasareff)
Date:
>>>>> "d" == derndorfer  <Martin> writes:

 d> hi,
 d> this is the part II of a question i already asked:

 d> i have some tables:
 d> create table css_class(nr int4, classname varchar(50));
 d> create table css_prop(nr int4, name varchar(50), val varchar(50),
 d> classnr int4);
 d> (css_prop.classnr foreign key-> css_class.nr)

 d> i would need a trigger on update and insert who takes all entries from
 d> the tables above and put them into a textfile in the following stype

 d> .n-th_of_css_class {
 d> n-th_of_css_prop.name(*) : n-th_of_css_prop.val(*);
 d> n+1-th_of_css_prop.name(*): [...]
 d> }
 d> .n+1-th_of_css_class { [...]

 d> with other words: i want to create a cascading style sheet out of the
 d> table:
 d> css files look something like that

 d> .cassname {
 d> property1 : value_prop1;
 d> property2 : value_prop2;
 d> [...]
 d> }
 d> [...]

 d> Can anyone help?
 d> a c-function would be ok too (_really_ think that i need one) but the
 d> file has to be created by the database itself.

 d> Idea for the future: whole html pages built out of the databased
 d> resulted by trigger/query combination. (not the question _yet_)

 d> MArtin

I think this is bad idea to build text file every time you change the
tables. What about external program (on C, Perl... etc) what rebuilds,
pehaps incrementally, file(s) with changed data? Or creating style
sheets and html pages 'on the fly' with any cgi-script?


--
Anatoly K. Lasareff              Email:       tolik@icomm.ru
Senior programmer

Re: [SQL] Triggers to create Tables

From
Martin Möderndorfer
Date:
Hm,

Stylesheets do not change often, it would be better to read them from
textfile than querying the database at the beginning of each html file
which includes it.

MArtin

"Anatoly K. Lasareff" wrote:
>
> >>>>> "d" == derndorfer  <Martin> writes:
>
>  d> hi,
>  d> this is the part II of a question i already asked:
>
>  d> i have some tables:
>  d> create table css_class(nr int4, classname varchar(50));
>  d> create table css_prop(nr int4, name varchar(50), val varchar(50),
>  d> classnr int4);
>  d> (css_prop.classnr foreign key-> css_class.nr)
>
>  d> i would need a trigger on update and insert who takes all entries from
>  d> the tables above and put them into a textfile in the following stype
>
>  d> .n-th_of_css_class {
>  d> n-th_of_css_prop.name(*) : n-th_of_css_prop.val(*);
>  d> n+1-th_of_css_prop.name(*): [...]
>  d> }
>  d> .n+1-th_of_css_class { [...]
>
>  d> with other words: i want to create a cascading style sheet out of the
>  d> table:
>  d> css files look something like that
>
>  d> .cassname {
>  d> property1 : value_prop1;
>  d> property2 : value_prop2;
>  d> [...]
>  d> }
>  d> [...]
>
>  d> Can anyone help?
>  d> a c-function would be ok too (_really_ think that i need one) but the
>  d> file has to be created by the database itself.
>
>  d> Idea for the future: whole html pages built out of the databased
>  d> resulted by trigger/query combination. (not the question _yet_)
>
>  d> MArtin
>
> I think this is bad idea to build text file every time you change the
> tables. What about external program (on C, Perl... etc) what rebuilds,
> pehaps incrementally, file(s) with changed data? Or creating style
> sheets and html pages 'on the fly' with any cgi-script?
>
> --
> Anatoly K. Lasareff              Email:       tolik@icomm.ru
> Senior programmer

Re: your mail

From
"Roderick A. Anderson"
Date:
On Fri, 19 Feb 1999, Eric Lee Green wrote:

> I am curious about the cost of triggers.
>
> The MySQL guys claim that they are very expensive. But if I want to put a

Pay now, pay later is more of an issue.  Using triggers means you code
once and then all accesses use the same rules.  If the rules change you
change the triggers not every application that accesses the database.  The
other issue is non-application access to the database.  Without triggers
anyone that can login to the database can make non-rule changes to the
data.  Triggers prevent this.
  This is from a modelling prespective.  The actual design of your
database my require you to go the low-road to get the performance you
need.  Though more memory, faster disk subsystems, and a faster CPU should
help without going that low-road.

Rod
--
Roderick A. Anderson
raanders@altoplanos.net               Altoplanos Information Systems, Inc.
Voice: 208.765.6149                            212 S. 11th Street, Suite 5
FAX: 208.664.5299                                  Coeur d'Alene, ID 83814


Stepping/Paging Through Rows

From
Dan Parker
Date:
Hi,

I've just started learning PostgreSQL (and SQL in general, really,
although I do have some experience with a proprietary RDBMS) and have been
wondering how I can page through records in a table or view.

I learned about cursors and they solved part of the problem - I created a
form with Perl/Tk with buttons to move forward a row and backwards a
row and that seems to be fine.

There are a couple of features I would like to have that I can't figure
out how I'd implement.  For example, lets say I want to add a new row to
the table.  I press an 'Add' button, the form goes blank, and I key in all
of the information.  I press an 'Update' button and behind the scenes
things whirl around and update the record in the database.  No problem.
But let's say now I want to return the user back to the browsing form and
place them on the row they just entered (while still being able to "page"
through the rows with the forward and back buttons).   I'm stuck. If I
create a new cursor, I'm back at the beginning of the table - there
doesn't seem to be a way to find a particular row and placing the
cursor there after creating the cursor.

Any help would be appreciated.  (I'd love a link to a good online SQL
resource.)

Dan


Re: [SQL] Stepping/Paging Through Rows

From
"Brett W. McCoy"
Date:
On Mon, 22 Feb 1999, Dan Parker wrote:

> I learned about cursors and they solved part of the problem - I created a
> form with Perl/Tk with buttons to move forward a row and backwards a
> row and that seems to be fine.
>
> There are a couple of features I would like to have that I can't figure
> out how I'd implement.  For example, lets say I want to add a new row to
> the table.  I press an 'Add' button, the form goes blank, and I key in all
> of the information.  I press an 'Update' button and behind the scenes
> things whirl around and update the record in the database.  No problem.
> But let's say now I want to return the user back to the browsing form and
> place them on the row they just entered (while still being able to "page"
> through the rows with the forward and back buttons).   I'm stuck. If I
> create a new cursor, I'm back at the beginning of the table - there
> doesn't seem to be a way to find a particular row and placing the
> cursor there after creating the cursor.

Have you looked at pgAccess yet?  It's an application written in Tcl/Tk
that allows you to build and administer PostgreSQL databases in a manner
very similar to MS-Access (hence the name, I guess...)  The author of
that software has probably already done a lot of what you are trying to
do.  It can be found at http://www.flex.ro/pgaccess.  I believe there may
even be a mailing list for it, but you can definitely get more direct
information on the INTERFACES mailing list.

Brett W. McCoy
                                         http://www.lan2wan.com/~bmccoy
-----------------------------------------------------------------------
Love at first sight is one of the greatest labor-saving devices the
world has ever seen.

----- BEGIN GEEK CODE BLOCK -----
Version: 3.12
GAT dpu s:-- a C++++ UL++++$ P+ L+++ E W++ N- o K- w--- O@ M-@ !V PS+++
PE Y+ PGP- t++ 5- X+ R+@ tv b+++ DI+++ D+ e>++ h+ r++ y++++
------ END GEEK CODE BLOCK ------