Re: [SQL] Sequence and nextval problem

2008-11-25 Thread Steve Midgley
At 11:20 PM 11/24/2008, [EMAIL PROTECTED] wrote: Message-Id: <[EMAIL PROTECTED]> From: ries van Twisk <[EMAIL PROTECTED]> To: Tk421 <[EMAIL PROTECTED]> In-Reply-To: <[EMAIL PROTECTED]> Subject: Re: Sequence and nextval problem Date: Mon, 24 Nov 2008 16:21:40 -0500 References: <[EMAIL PROTECTED]>

Re: [SQL] Sequence and nextval problem

2008-11-24 Thread Craig Ringer
Earlier, Craig Ringer wrote: for sample operator/cast definitions. There are some notes in the top of the "passthrough.txt" module I attached that explain the ODBC driver options you'll want. Also, note that in the message I just posted the function DSN() must be adapted to include the appro

Re: [SQL] Sequence and nextval problem

2008-11-24 Thread Craig Ringer
Tk421 wrote: Hello everybody. I've got an vb aplication that uses an Access database. I'm trying to convert the database to postgres. The conversion was done ok, but i've got a little problem that i don't know how to solve. Let's see if anyone can help me. The conversion from acces

Re: [SQL] Sequence and nextval problem

2008-11-24 Thread ries van Twisk
On Nov 24, 2008, at 2:12 PM, Tk421 wrote: Hello everybody. I've got an vb aplication that uses an Access database. I'm trying to convert the database to postgres. The conversion was done ok, but i've got a little problem that i don't know how to solve. Let's see if anyone can help me

Re: [SQL] Sequence and nextval problem

2008-11-24 Thread Scott Marlowe
On Mon, Nov 24, 2008 at 12:12 PM, Tk421 <[EMAIL PROTECTED]> wrote: > Hello everybody. > > I've got an vb aplication that uses an Access database. I'm trying to > convert the database to postgres. The conversion was done ok, but i've got a > little problem that i don't know how to solve. Let's s

[SQL] Sequence and nextval problem

2008-11-24 Thread Tk421
Hello everybody. I've got an vb aplication that uses an Access database. I'm trying to convert the database to postgres. The conversion was done ok, but i've got a little problem that i don't know how to solve. Let's see if anyone can help me. The conversion from access database to

Re: [SQL] sequence number in a result

2008-10-09 Thread Relyea, Mike
> Is there a function or special system label I can use that would generate a sequence number in the returning result set? Would something like this work for you? CREATE TEMP SEQUENCE foo; SELECT a, b, c, nextval('foo') AS order FROM t1 ORDER BY a; Mike Relyea Product Development Engineer Xe

Re: [SQL] sequence number in a result

2008-10-09 Thread Tom Lane
"Campbell, Lance" <[EMAIL PROTECTED]> writes: > Is there a function or special system label I can use that would > generate a sequence number in the returning result set? The usual hack is a temporary sequence: regression=# create temp sequence s1; CREATE SEQUENCE regression=# select nextval('s1'

Re: [SQL] sequence number in a result

2008-10-09 Thread Oliveiros Cristina
: Thursday, October 09, 2008 5:48 PM Subject: Re: [SQL] sequence number in a result Howdy, Lance. I had that problem about a year ago, and AFAIK there is no solution, at least not in SQL Standard. What I did was something like SELECT a,b,c,count(y.a) as order FROM t1 x , t1 y WH

Re: [SQL] sequence number in a result

2008-10-09 Thread Oliveiros Cristina
t;iPages\" ) " + "OR (resumo1.\"iPages\" = resumo2.\"iPages\" " + "AND resumo1.\"IDSiteResume\" <= resumo2.\"IDSiteResume\")) " + // Tinha e tem IDSiteResume "GROUP BY resumo1.\"iPages\",resumo1.\"iUniq

[SQL] sequence number in a result

2008-10-09 Thread Campbell, Lance
Say I have the following SQL statement: SELECT a, b, c FROM t1 ORDER BY a; Is there a function or special system label I can use that would generate a sequence number in the returning result set? Example: SELECT a, b, c, SOMELABEL as order FROM t1 ORDER BY a; Result: ab c

Re: [SQL] Sequence vs. Index Scan

2007-05-07 Thread Aaron Bono
On 5/7/07, Tom Lane <[EMAIL PROTECTED]> wrote: Andrew Sullivan <[EMAIL PROTECTED]> writes: > On Sun, May 06, 2007 at 01:45:54PM -0500, Aaron Bono wrote: >> So my conclusion is that the function is being treated as volatile even >> though it is stable because the number of records is small. > I

Re: [SQL] Sequence vs. Index Scan

2007-05-07 Thread Tom Lane
Andrew Sullivan <[EMAIL PROTECTED]> writes: > On Sun, May 06, 2007 at 01:45:54PM -0500, Aaron Bono wrote: >> So my conclusion is that the function is being treated as volatile even >> though it is stable because the number of records is small. > I don't think that's the issue. If this is depende

Re: [SQL] Sequence vs. Index Scan

2007-05-07 Thread Andrew Sullivan
On Sun, May 06, 2007 at 01:45:54PM -0500, Aaron Bono wrote: > Then I inserted 150 more records in the slow schema and pow - it started > working like the fast schema. > > So my conclusion is that the function is being treated as volatile even > though it is stable because the number of records i

Re: [SQL] Sequence vs. Index Scan

2007-05-06 Thread Aaron Bono
On 5/5/07, Jaime Casanova <[EMAIL PROTECTED]> wrote: On 5/5/07, Aaron Bono <[EMAIL PROTECTED]> wrote: > On 5/5/07, Tom Lane <[EMAIL PROTECTED]> wrote: > > "Aaron Bono" <[EMAIL PROTECTED]> writes: > > > 9. -> Seq Scan on branch (cost= 0.00..4.72 > rows=1 > > > width=12

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Jaime Casanova
On 5/5/07, Aaron Bono <[EMAIL PROTECTED]> wrote: On 5/5/07, Tom Lane <[EMAIL PROTECTED]> wrote: > "Aaron Bono" <[EMAIL PROTECTED]> writes: > > 9. -> Seq Scan on branch (cost=0.00..4.72 rows=1 > > width=1281) (actual time= 130129.988..157492.057 rows=1 loops=1) > > 10.

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Aaron Bono
On 5/5/07, Tom Lane <[EMAIL PROTECTED]> wrote: "Aaron Bono" <[EMAIL PROTECTED]> writes: > 9. -> Seq Scan on branch (cost=0.00..4.72rows=1 > width=1281) (actual time=130129.988..157492.057 rows=1 loops=1) > 10.Filter: ((start_day <= now(

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Aaron Bono
On 5/5/07, Andrew Sullivan <[EMAIL PROTECTED]> wrote: On Sat, May 05, 2007 at 05:00:53PM -0500, Aaron Bono wrote: > We don't allow deletes and updates are fairly infrequent. I also did a > vacuum analyze to no effect. How do you "not allow" deletes? Permissions are set on the tables to onl

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Aaron Bono
On 5/5/07, Tom Lane <[EMAIL PROTECTED]> wrote: "Aaron Bono" <[EMAIL PROTECTED]> writes: > 9. -> Seq Scan on branch (cost=0.00..4.72rows=1 > width=1281) (actual time=130129.988..157492.057 rows=1 loops=1) > 10.Filter: ((start_day <= now(

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Andrew Sullivan
On Sat, May 05, 2007 at 05:00:53PM -0500, Aaron Bono wrote: > > They have different data. The fast one has about 150 rows and the slow one > has about 40 rows. The field in question here, the branch_id, is a > BIGSERIAL in both. I'd be astonished if a table of 40 rows ever got index scanned.

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Tom Lane
"Aaron Bono" <[EMAIL PROTECTED]> writes: > 9. -> Seq Scan on branch (cost=0.00..4.72 rows=1 > width=1281) (actual time=130129.988..157492.057 rows=1 loops=1) > 10.Filter: ((start_day <= now()) AND > ((end_day IS NULL) OR (end_day >= now())

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Aaron Bono
On 5/5/07, Andrew Sullivan <[EMAIL PROTECTED]> wrote: On Sat, May 05, 2007 at 04:05:52PM -0500, Aaron Bono wrote: > I have two schemas, both with the exact same DDL. One performs great and Do they have the same data? They have different data. The fast one has about 150 rows and the slow o

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Andrew Sullivan
On Sat, May 05, 2007 at 04:05:52PM -0500, Aaron Bono wrote: > I have two schemas, both with the exact same DDL. One performs great and Do they have the same data? > I have > checked and there IS an index, specifically a primary key index, on the > branch_id in both schemas so I cannot figure ou

[SQL] Sequence vs. Index Scan

2007-05-05 Thread Aaron Bono
I have two schemas, both with the exact same DDL. One performs great and the other has problems with a specific query: SELECT * FROM branch_active_vw WHERE branch_id = get_branch_for_zip ( '22151' ) ORDER BY branch_name ; I am not defining the view here because the explain plans show the rea

Re: [SQL] Sequence vs Serial

2007-04-01 Thread Tom Lane
Scott Marlowe <[EMAIL PROTECTED]> writes: > Daniel CAUNE <[EMAIL PROTECTED]> Said: >> I was wondering when it is better to choose sequence, and when >> it is better to use serial. > One reason for using serial versus sequence is that a serial gives you > automatic dependency tracking. Note that

Re: [SQL] Sequence vs Serial

2007-04-01 Thread Scott Marlowe
Daniel CAUNE <[EMAIL PROTECTED]> Said: > I was wondering when it is better to choose sequence, and when > it is better to use serial. The serial type is a sequence with > default parameters (http://www.postgresql.org/docs/8.2/static/datatype-numeric.html#DATATYPE-SERIAL). > Actually, I never

[SQL] Sequence vs Serial

2007-03-31 Thread Daniel CAUNE
Hi, I was wondering when it is better to choose sequence, and when it is better to use serial. The serial type is a sequence with default parameters (http://www.postgresql.org/docs/8.2/static/datatype-numeric.html#DATATYPE-SE RIAL). Actually, I never use serial - I prefer sequence for some re

Re: [SQL] Sequence of SQL command execution involving triggers and stored procedures.

2004-09-18 Thread Tom Lane
"Omkar Rath" <[EMAIL PROTECTED]> writes: > Say there is a stored procedure i.e FUNCTION sp_foo(...) which has say, > SQL commands (any of SELECT,INSERT,UPDATE,DELETE) in its body, say S1 > followed by S2 then S3 Furthermore, execution of statement S2 > results in trigger functions getting invok

[SQL] Sequence of SQL command execution involving triggers and stored procedures.

2004-09-18 Thread Omkar Rath
Title: Message I am observing the following:   Say there is a stored procedure i.e FUNCTION sp_foo(...) which has say, SQL commands (any of SELECT,INSERT,UPDATE,DELETE) in its body, say S1 followed by S2 then S3 Furthermore, execution of statement S2 results in trigger functions getting

Re: [SQL] sequence

2003-08-15 Thread Tom Lane
"cristi" <[EMAIL PROTECTED]> writes: > What is wrong here? > insert into table_name (field_name) values (select > setval('sequence_name')-1) as currval); Either too few parentheses, or too many ;-) You could write this as an INSERT/SELECT: insert into table_name (field_name) select setval('seq

Re: [SQL] sequence

2003-08-15 Thread Bertrand Petit
On Fri, Aug 15, 2003 at 12:32:36PM +0300, cristi wrote: > What is wrong here? > > insert into table_name (field_name) values (select > setval('sequence_name')-1) as currval); This should be better: INSERT INTO table_name (field_name) VALUES (nextval('sequence_name')); -- %!PS 2

Re: [SQL] sequence

2003-08-15 Thread Dennis Björklund
On Fri, 15 Aug 2003, cristi wrote: > What is wrong here? > > insert into table_name (field_name) values (select > setval('sequence_name')-1) as currval); Your probably want this instead: insert into table_name (field_name) values (nextval('sequence_name')); The reason why your insert fail ab

[SQL] sequence

2003-08-15 Thread cristi
What is wrong here? insert into table_name (field_name) values (select setval('sequence_name')-1) as currval); ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster

Re: [SQL] SEQUENCE and PRIMARY KEY

2003-07-03 Thread Rod Taylor
> >A trigger (maybe a rule) is the way to go about this. > > > >The alternative is to teach the bad clients to use DEFAULT rather than > >NULL when they expect the GENERATOR to create the value for them. > > > Hmm, Rod, there really seems a demand for the GENERATOR feature :-) > Do you see any perf

Re: [SQL] SEQUENCE and PRIMARY KEY

2003-07-02 Thread Rod Taylor
On Wed, 2003-07-02 at 11:30, Ralf Werny wrote: > Hi, > many clients like webmin and openoffice makes an > INSERT NULL if i give no value for a field because it is a sequence. > Is there a better way to solve this problem as using a trigger ? A trigger (maybe a rule) is the way to go about th

[SQL] SEQUENCE and PRIMARY KEY

2003-07-02 Thread Ralf Werny
Hi, many clients like webmin and openoffice makes an INSERT NULL if i give no value for a field because it is a sequence. Is there a better way to solve this problem as using a trigger ? CREATE TABLE test ( id integer PRIMARY KEY ); CREATE SEQUENCE test_seq_id MINVALUE

Re: [SQL] sequence question

2003-01-27 Thread Rod Kreisler
t too worried about figuring it out... HTH Rod > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED]]On Behalf Of Marie G. Tuite > Sent: Monday, January 27, 2003 3:06 PM > To: Pgsql-Sql@Postgresql. Org > Subject: [SQL] sequence question > > >

[SQL] sequence question

2003-01-27 Thread Marie G. Tuite
Hey there, Does anybody have a nice way to identify what table.column is using a particular sequence on a database-wide basis? --Thanks. ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Re: [SQL] Sequence name length

2002-07-16 Thread Rudi Starcevic
Hi Tom, Here is the output from 'select version()' PostgreSQL 7.2 on i686-pc-linux-gnu, compiled by GCC 2.95.2 Cheers Rudi. Tom Lane wrote: >Rudi Starcevic <[EMAIL PROTECTED]> writes: > > >>Just a quick one on the length of the name of a sequence. >>... >>However the sequence created is nam

Re: [SQL] Sequence name length

2002-07-16 Thread Christopher Kings-Lynne
> > However the sequence created is named : > > eselect_maincategory_maincat_id ( the '_seq' is lopped off ) > > What version are you running? Anything recent will keep the '_seq' > and lop elsewhere. Not if he's manually creating a sequence name that's too long - it will just truncate it me

Re: [SQL] Sequence name length

2002-07-16 Thread Tom Lane
Rudi Starcevic <[EMAIL PROTECTED]> writes: > Just a quick one on the length of the name of a sequence. > ... > However the sequence created is named : > eselect_maincategory_maincat_id ( the '_seq' is lopped off ) What version are you running? Anything recent will keep the '_seq' and lo

Re: [SQL] Sequence name length

2002-07-16 Thread Christopher Kings-Lynne
: create table blah ( maincat_id SERIAL ); Chris > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED]]On Behalf Of Rudi Starcevic > Sent: Wednesday, 17 July 2002 10:39 AM > To: [EMAIL PROTECTED] > Subject: [SQL] Sequence name length > > &g

[SQL] Sequence name length

2002-07-16 Thread Rudi Starcevic
Hi, Just a quick one on the length of the name of a sequence. I have some table with long(ish) names like : eselect_maincategory The primary key is named : maincat_id When I create the table the sequence sql looks like nextval('"eselect_maincategory_maincat_id_seq"'::text) Howeve

Re: [SQL] sequence chages after firing update

2002-06-26 Thread Rajesh Kumar Mallah.
dear subha, Use explicit ORDER BY if u want to order the records by some column. otherwise the order of output from a select stmt is undefined. bu generally it is found the the last updated record comes last. On Wednesday 26 June 2002 17:17, Subhashini Karthikeyan wrote: > hi all > > > In post

Re: [SQL] sequence chages after firing update

2002-06-26 Thread Stephan Szabo
On Wed, 26 Jun 2002, Subhashini Karthikeyan wrote: > In postgresql 7.1.3 > > i am updateing a row. it is a 4th record. > after updation if i am firing a select query it is > coming as a last record ..what shall i do to avoid > that.. > any help appriciated If I understand the complaint, use an

[SQL] sequence chages after firing update

2002-06-26 Thread Subhashini Karthikeyan
hi all In postgresql 7.1.3 i am updateing a row. it is a 4th record. after updation if i am firing a select query it is coming as a last record ..what shall i do to avoid that.. any help appriciated thankz in advance regards subha __ Do You Ya

Re: [SQL] Sequence behaviour.

2001-06-19 Thread Grant
> > binary_data=# create sequence test; > > CREATE > > binary_data=# select nextval('test'); > > NOTICE: test.nextval: sequence was re-created > > Um, how did you get that NOTICE? I don't see it. This is version 7.0.3. I deleted the sequence first. > Anyway, the answer to your question is tha

Re: [SQL] Sequence behaviour.

2001-06-18 Thread Tom Lane
Grant <[EMAIL PROTECTED]> writes: > Why is the following like it is? I would think that nextval would return 2 > in both instances, am I missing something here? :) Thanks! > binary_data=# create sequence test; > CREATE > binary_data=# select nextval('test'); > NOTICE: test.nextval: sequence was

[SQL] Sequence behaviour.

2001-06-18 Thread Grant
Why is the following like it is? I would think that nextval would return 2 in both instances, am I missing something here? :) Thanks! binary_data=# create sequence test; CREATE binary_data=# select nextval('test'); NOTICE: test.nextval: sequence was re-created nextval - 1 (1 row)

Re: [SQL] sequence problem

2001-05-21 Thread Stephan Szabo
On Mon, 21 May 2001, gabi munteanu wrote: > I have the following problem. > > I have a table [friends] and it looks like this: >id serial >name varchar(25) >phone varchar(15) > After I created it tehre is also a sequence that generates me the ids > friens_id_s

[SQL] sequence problem

2001-05-21 Thread gabi munteanu
I have the following problem. I have a table [friends] and it looks like this: id serial name varchar(25) phone varchar(15) After I created it tehre is also a sequence that generates me the ids friens_id_seq Let's say I have 5 records. If I remove the 3th my ids