[SQL] Need more examples (was "session variable")

2003-09-20 Thread Miko O Sullivan
On Wed, 17 Sep 2003 17:23:05 -0400, Tom Lane wrote > [EMAIL PROTECTED] (Miko O'Sullivan) writes: > > Unfortunately in the 7.2.x version I have available, EXECUTE does not > > allow "select into". The docs suggests a technique for using a FOR > > loop to extract information from an EXECUTE, but the

Re: [SQL] how to get decimal to date form

2003-09-20 Thread David Brown
Okay thanks, this is how I ended up doing it: TO_DATE(SUBSTR(TO_CHAR(rec_num,999),1,6),'0YMMDD') AS Date Another question though... I have a field that is of type numeric so when I want to divide it like this: SUM(vc_elapsed_time)/60.0 postgre complains "Unable to identify an operator '/'

[SQL] Unique Constraint Based on Date Range

2003-09-20 Thread Andrew Milne
I'm looking to apply a unique constraint to a table such that field A must be unique based on the date range from Field B to Field C. This is for a rate based service model whereby, for example, $5 is worth 1 hour of Internet access. But next week, because of increased competition, $5 is wort

[SQL] Reg: Firing Trigger when a particular column value get changed

2003-09-20 Thread Thilak babu
Hi All, I have a scnerio as to fire a trigger when i update a particular column in a table. Please do help me out in getting thro this. Thanks in advance, Thilak . ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ?

Re: [SQL] auto_increment

2003-09-20 Thread btober
> How to Create auto_increment field in PostreSQL. Its called the SERIAL datatype: create table test_table ( field1 serial, constraint test_table_pkey primary key (field1)); > Can I create them using Trigger. Yes, alternatively, but I'm told that is not recommended because the server source c

Re: [SQL] Automated Backup

2003-09-20 Thread btober
> >> Is there a way to automate the backup databases using pg_dump (like >> in SQL server)? > Ha! Why would you want to do ANYTHING "like in SQL server"! ;) You can do you back-ups very nicely using cron and a bash script: bash-2.05a$ crontab -l # DO NOT EDIT THIS FILE - edit the master and rein

Re: [SQL] [ADMIN] Error with functions

2003-09-20 Thread Jean-Michel Chabanne
[EMAIL PROTECTED] a écrit : Hey, create or replace function sample(varchar,int) returns varchar as' declare data alias for $1; size alias for $2; begin return substr(data,(length(data)-size)+1,length(data)); end; ' language 'plpgsql'; WARNING: pl

Re: [SQL] [ADMIN] Error with functions

2003-09-20 Thread Tom Lane
[EMAIL PROTECTED] writes: > CREATE FUNCTION add_one (integer) RETURNS INTEGER AS ' > BEGIN > RETURN $1 + 1; > END; > ' LANGUAGE 'plpgsql'; > The expected ouput of the above function should be 11 when we pass the 10 t= > o it but it returns 1. Works fine for me: regression=# CR

Re: [SQL] sub query

2003-09-20 Thread Peter Eisentraut
Martin Kuria writes: > Hi again I have this problem when I try to run this query, how can I rewrite > it for it to work. > > SELECT o.item_order_num,SUM(o.item_quantity + o.item_product_id) As total, > o.item_status > FROM soko_product p, soko_ordered_item o > WHERE p.product_id = o.item_product_i

Re: [SQL] auto_increment

2003-09-20 Thread Christopher Browne
In the last exciting episode, [EMAIL PROTECTED] ("Muhyiddin A.M Hayat") wrote: > Ok, but if i do rollback, the auto_increment don't roolback. Right, it's not supposed to. Think about the situation where you have 5 clients connecting to the database and adding records to this table. The current f

[SQL] sub query

2003-09-20 Thread Martin Kuria
Hi again I have this problem when I try to run this query, how can I rewrite it for it to work. SELECT o.item_order_num,SUM(o.item_quantity + o.item_product_id) As total, o.item_status FROM soko_product p, soko_ordered_item o WHERE p.product_id = o.item_product_id GROUP BY o.item_order_num ORDER

Re: [SQL] auto_increment

2003-09-20 Thread Richard Huxton
On Saturday 20 September 2003 11:14, Muhyiddin A.M Hayat wrote: > Where/How can i put this below sql statement, to set value of > guest_guest_id_seq before i do insert to table > SELECT setval('guest_guest_id_seq', max(guest.guest_id)) FROM guest; > > i have been try > > CREATE TRIGGER "before_in

Re: [SQL] Error with functions

2003-09-20 Thread shyamperi
5:08p Dear All, When I am executing any function with parameter.. I am unable to access them. So, I would be thankful if, anyone can help me in teaching this aspect. CREATE FUNCTION add_one (integer) RETURNS INTEGER AS ' BEGIN RETURN $1 + 1; END; ' LANGUAGE 'plpgsql'; The expected

Re: [SQL] auto_increment

2003-09-20 Thread Martin Marques
Why do you want it to rollback? El Sáb 20 Sep 2003 05:43, Muhyiddin A.M Hayat escribió: > Ok, but if i do rollback, the auto_increment don't roolback. > How to use nextval(), currval() and setval() functions. > > - Original Message - > From: Cavit Keskin > To: 'Muhyiddin A.M Hayat' >

Re: [SQL] auto_increment

2003-09-20 Thread Martin Marques
El Sáb 20 Sep 2003 03:23, Oliver Elphick escribió: > On Sat, 2003-09-20 at 06:10, Muhyiddin A.M Hayat wrote: > > How to Create auto_increment field in PostreSQL. > > Can I create them using Trigger. > > Use the SERIAL datatype. See also the functions nextval(), currval() > and setval(). Also to a

Re: [SQL] auto_increment

2003-09-20 Thread Muhyiddin A.M Hayat
Where/How can i put this below sql statement, to set value of guest_guest_id_seq before i do insert to table SELECT setval('guest_guest_id_seq', max(guest.guest_id)) FROM guest; i have been try CREATE TRIGGER "before_insert_guest_update_room_number" BEFORE INSERT ON "public"."guest" FOR EACH RO

Re: [SQL] auto_increment

2003-09-20 Thread Richard Huxton
On Saturday 20 September 2003 09:43, Muhyiddin A.M Hayat wrote: > Ok, but if i do rollback, the auto_increment don't roolback. It's not supposed to. > How to use nextval(), currval() and setval() functions. Something like: INSERT INTO my_table(nextval('my_sequence_name'),'aaa',1); But you'll g

Re: [SQL] auto_increment

2003-09-20 Thread Muhyiddin A.M Hayat
Ok, but if i do rollback, the auto_increment don't roolback. How to use nextval(), currval() and setval() functions.   - Original Message - From: Cavit Keskin To: 'Muhyiddin A.M Hayat' Sent: Saturday, September 20, 2003 2:15 PM Subject: RE: [SQL] auto_increment

Re: [SQL] Error with functions

2003-09-20 Thread shyamperi
Hey, PostgreSQL 7.3 on i686-pc-linux-gnu, compiled by GCC 2.96 But, I am getting error when I am using the alias key word. And also when I try to create a C function for the same and excute I am getting the following error ERROR: Memory exhausted in AllocSetAlloc(677865842) And, I am allocating

Re: [SQL] Error with functions

2003-09-20 Thread Tomasz Myrta
Hey, create or replace function sample(varchar,int) returns varchar as' declare data alias for $1; size alias for $2; begin return substr(data,(length(data)-size)+1,length(data)); end; ' language 'plpgsql'; WARNING: plpgsql: ERROR during compil