inicio mail me! sindicaci;ón

myles henderson

it is myles henderson

Archive for sql

PostgreSQL Insert Function Generator

I like the plpgsql procedural language for PostgreSQL more than it is appropriate to like a procedural language. I find the reward:effort ratio to be quite high. Since one can do so many cool things with it, why waste time writing boring insert functions for tables?

Here’s my plpgsql function which generates the create function statements for tables in a database.

download the function

The above code is a rolled back transaction which creates the generator function and then calls it so that one can view the results. By itself, it leaves no lasting impact on the database.

The insert generator accepts no input and returns a varchar. The string it returns can be executed against the database to create one function for each table in the database.

The newly created functions will accept as input all of the fields of the table and returns the primary key of the new record or 0 (zero) if no record was inserted.

The insert generator is limited to working with somewhat simple tables, as it is not aware of multiple column primary keys.

The resulting functions assume that they are being supplied clean input. You should do something to scrub your data before handing it off to the insert functions generated using this method. There’s a lot else that this doesn’t do, so you should use it at your own risk. I make no guarantees that it will work in your environment or that it is suitable for any particular use.

I will post a function which generates update functions in the coming days.

I have tested this code on against PostgreSQL versions 8.1.9 and 7.4.18.

Not Acceptable

I’m trying to post a SQL query. But this motherbitch of a wordpress install, won’t let me. I thought maybe i messed something on the post.php file so i upgraded to version 2. Same thing. I’m sure that this POS post goes through.

An appropriate representation of the requested resource /wp-admin/post.php could not be found on this server.


UPDATE:Spme people have been sreaching for the error that I received and have ended up here. Sorry about that. Just to let both of you know, I received the error when I was trying to post a .sql script to this wordpress 2.0 installation through the administrative interface.

Apache/1.3.34 Server at www.myleshenderson.com Port 80