Re: [SQL] help with version checking

2006-12-29 Thread Karsten Hilbert
In GNUmed we have created a function gm_concat_table_structure() in http://cvs.savannah.gnu.org/viewcvs/gnumed/gnumed/server/sql/gmSchemaRevisionViews.sql?rev=1.6root=gnumedview=log which returns a reproducable, human-readable TEXT concatenation of all the relevant parts of

Re: [SQL] help with version checking

2006-12-29 Thread Arnau
Hi all, Thanks for all replies, taking into account all your suggestions and my google research I arrived to the next script. I'd like to know your opinion. Hopefully this will be useful for somebody else. --used to stop the script execution on any error

Re: [SQL] help with version checking

2006-12-29 Thread Chris Dunworth
I'd probably make a small change to make this a little cleaner. Specifically, change check_version() to take an argument, which is the needed version, and check this against the current value in agenda_version, throwing the exception if they don't match. Once you've written this, you'll never

[SQL] help with version checking

2006-12-28 Thread Arnau
Hi all!, I've got the following problem and I don't know how to solve it in PostgreSQL. I'd like to add a version checking to my db scripts. That is, I have the db creation scripts and the changes/upgrade script, and there is a table inside each db that holds the version of script

Re: [SQL] help with version checking

2006-12-28 Thread Arnau
Hi Daniel, You should define a PL/PGSQL function such as: CREATE OR REPLACE FUNCTION check_version() RETURNS void AS $$ DECLARE v_version VARCHAR; BEGIN SELECT version INTO v_version FROM version WHERE id = 1; IF v_version '1.0.0.0' THEN RAISE EXCEPTION 'This script needs

Re: [SQL] help with version checking

2006-12-28 Thread Tom Lane
Arnau [EMAIL PROTECTED] writes: I don't want, if it's possible, to create a function. Unlike Oracle, PG makes a strong distinction between SQL and programmable languages (including plpgsql). You can't write plpgsql code without putting it into a function. regards,

Re: [SQL] help with version checking

2006-12-28 Thread Arnau
Tom Lane wrote: Arnau [EMAIL PROTECTED] writes: I don't want, if it's possible, to create a function. Unlike Oracle, PG makes a strong distinction between SQL and programmable languages (including plpgsql). You can't write plpgsql code without putting it into a function.

Re: [SQL] help with version checking

2006-12-28 Thread Arnau
Arnau wrote: Tom Lane wrote: Arnau [EMAIL PROTECTED] writes: I don't want, if it's possible, to create a function. Unlike Oracle, PG makes a strong distinction between SQL and programmable languages (including plpgsql). You can't write plpgsql code without putting it into a function.

Re: [SQL] help with version checking

2006-12-28 Thread Chris Dunworth
Can you do the whole thing inside a transaction context (both the version check and the updates)? The exception should cause the transaction to bail out, and the updates won't proceed. Thus: BEGIN; SELECT check_version(); UPDATE agenda_version set version = '1.0.0.1' where id = 1; COMMIT; I

Re: [SQL] help with version checking

2006-12-28 Thread Daniel CAUNE
I tried to do the following in PostgreSQL: DECLARE v_version VARCHAR; BEGIN SELECT version INTO v_version FROM version WHERE id = 1; IF v_version ''1.0.0.0'' THEN RAISE EXCEPTION ''This script needs Agenda version 1.0.0.0, detected version %'', v_version; END IF;