This is a (full ACID) SQL database and it is OpenSource. It comes with binding for many languages, including one for Tcl. The database has its home at http://www.postgresql.org
Starting with version 8.0, the server side of Postgres is also available for native Windows (NT, 2000, XP, etc. variants only). Previous versions required Cygwin to run the PostgreSQL server. Client access libraries have always been available on Win32.
PostgreSQL and Tcl have a long history with each other. Tcl bindings such as pgtcl are available for communicating with the server from Tcl scripts, while pltcl is available inside the running server to script triggers and stored procedures.
One of PG's technical advantages among databases is its asynchronous notification feature. Tcl's event loop nicely complements this.
Update 11Aug04 PS: Sadly, starting with version 8.0, the PostreSQL team has decided to drop the Tcl client library from the core distribution (but not the Tcl support!). The JDBC client driver was also scrapped from the core. Both were offloaded to http://gborg.postgresql.org and then to http://pgfoundry.org (Tcl: pgtcl:[L1 ] pgintcl:[L2 ] pgtcl-ng:[L3 ]) It actually seems all client libraries have been removed from the core, even the C library.
pgtcl and pgtcl-ng have binaries available for windows. pgintcl is platform-independent.
Access a Postgresql database from Tcl:
This Tcl binding comes as a (shared and/or static) library and on a Linux-System you can easily build a package from that. You only need to create a directory under, say, /usr/lib/tcl (replace this by a path searched by your local Tcl/Tk installation), place a copy of the library there, and go ahead. Here's an example:
> cd /usr/lib/tcl8.3 > mkdir postgresql > cp /usr/local/pgsql/lib/libpgtcl.so.2.2 postgresql/libpgtcl.so > cd postgresql > tclsh % pkg_mkIndex /usr/lib/tcl8.3/postgresql *.so % exit
This produced a pkgIndex.tcl file with all needed information to use the package. I then use the package with a simple
package require Pgtcl
in my applications.
Karl Lehenbauer - 2004-11-19 - That's a bit gross. If you build and install libpgtcl using configure; make; make install, that should be all you need.
2003-12-08 Is there something equal for a windows system?
BR - 2003-12-10 - I always use TclODBC for all my database access, this works fine for PostgreSQL.
Artur Trzewik 2003-12-11 TclODBC lacks some functions that are possible with Pgtcl. That are: movable cursor (seek command on cursor position) and nested queries in one database handle. I think they are possible in ODBC but not implemented in TclODBC.
Brett Schwarz 2004-09-23: There are windows binaries at the gborg site that you can download to run pgtcl [L4 ]
I found, that the syntax of the Pgtcl commands are not the Tcl way. So I wrote a little wrapper around the commands provided by the Pgtcl package to make them more tcl-like:
proc pg {cmd args} { switch $cmd { connect {pg_connect [lindex $args end]} disconnect {pg_disconnect [lindex $args end]} execute {pg_exec [lindex $args 0] [lindex $args 1]} getrow {pg_result [lindex $args 0] -getTuple [lindex $args 1]} clear {pg_result [lindex $args 0] -clear} status {pg_result [lindex $args 0] -status} rowcount {pg_result [lindex $args 0] -numTuples} } }
This adds a command pg to Tcl which I like far more than the original one. Instead of saying
pg_connect "mydb" pg_disconnect $myHandle pg_result $myResult -clear
I just type
pg connect "mydb" pg disconnect $myHandle pg clear $myResult
Please note, that there is no error handling and checking in the command pg and you can easily type in wrong things. It would be best to put this command in it's own namespace and provide for error checking etc. You could even add more funcionality like a loop command for query results like in nstcl
What: PostgreSQL Where: http://www.postgresql.org/ http://odbc.postgresql.org/ http://www.ids.net/%7Ebjepson/freeODBC/ http://www.openlinksw.com/ http://www.demon.co.uk/finder/postgres/ http://www.ucolick.org/%7Ede/tcl_syb/wisql.html ftp://rocker.sch.bme.hu/pub/mirrors/postgreSQL/ http://www.illustra.com/ http://aldev.8m.com/ http://aldev.webjump.com/ http://www3.bcity.com/aldev/ ftp://ftp.redhat.com/ http://www.pgsql.com/ http://www.askesis.nl/AskesisPostgresIndex.html http://members.spree.com/technology/aldev/ http://field.medicine.adelaide.edu.au/%7Ecolin/libtclpq/ ftp://field.medicine.adelaide.edu.au/pub/libtclpq/libtclpq.tgz Description: PostgreSQL is a derivitive of POSTGRES 4.2, converted to ANSI C. POSTGRES is a database management system. It is compliant with ANSI SQL92 and SQL89. It supports a number of enhancements, such as inheritance, declaritive queries, optimization, concurrency control, transactions, mult-user support, user defined operators, types, functions, and access methods. APIs exist for C, C++, Java, Perl4, Perl5, Python, SQL and Tcl. A JDBC driver is also included in the main distribution. Free drivers for ODBC are available as a separate download. A commercial version of PostgreSQL is available via Illustra, Inc. The most recent version is 7.4. Updated: 12/2003 Contact: mailto:[email protected] (PostGres95 mailing list)
pgintcl is another Tcl interface to PostgreSQL, which is itself written entirely in Tcl and does not rely on libpq.
http://pgintcl.projects.postgresql.org/
I got caught out by a problem using pg_execute. pg_execute evaluates the supplied script for each row of the result. I was appending each result to a list. The problem was that the speed scaled very poorly as the number of records increased. I boiled it down to this test case:
set a "" time [list pg_execute pgsql5 "SELECT * FROM journal LIMIT 1000" { append a {23456789012345678901234567890123456789012345678901234567890}}]
It turned out to be because append was, of course, returning the whole variable, which was quite big. pg_execute was internally doing something slow with what was returned. Changing the test case to:
set a "" time [list pg_execute pgsql5 "SELECT * FROM journal LIMIT 1000" { append a {23456789012345678901234567890123456789012345678901234567890} ; list}]
fixed the problem. This reduced the time to read 10,000 records from about half a minute to 170 milliseconds!
20031113 MB
Jerry Levan makes a MacOS-oriented client available through a site [L5 ] he maintains.
ljb supports Pgtcl-NG [L6 ].
Pronounced "post-grehs-Q-L", though in most other cases SQL is pronounced as "sequel" -FW
There are some notes on the pgtcl page that explain some of version 1.5 features.
escargo 15 Mar 2006 - Here's a link to an article that mentions PostgreSQL scripting with Tcl: http://searchopensource.techtarget.com/originalContent/0,289142,sid39_gci1172668,00.html