[SQL] Alternative Serial

2007-03-11 Thread Ezequias Rodrigues da Rocha

Hi list,

I know that serials must be created like this.

Create the Serial

Create a field table and reffers to the pre-created serial.

Now I noticed that it is possible to use the default value. I am almost
quite sure that this is an alternative way and non polite.

I would like to know if I am correct and what does it means:

nextval('mySerial_id'::regclass)

What is regclass ?

Regards ,
--
Ezequias Rodrigues da Rocha
http://ezequiasrocha.blogspot.com/
use Mozilla Firefox:http://br.mozdev.org/firefox/


Re: [SQL] [pgadmin-support] Alternative Serial

2007-03-11 Thread Ezequias Rodrigues da Rocha

Yes you are right, I means sequences.

The second way is better for me that have Id (PK) fields not  defined  as
Sequences. Now it is much more difficult to change the  type of my PK than
define a Default value. I am just concerned about the consistency of this
sequence. Could you make me more easy ?

And about the cast I have found ?

nextval('mySerial_id'::regclass)

I ask again. What is regclass ? What does it really is.

Ezequias

2007/3/11, Milen A. Radev <[EMAIL PROTECTED]>:


Ezequias Rodrigues da Rocha написа:
> Hi list,
>
> I know that serials must be created like this.

Actually no.

> Create the Serial

There is no db object 'Serial' you could create independently - you
probably mean 'sequence'.

>
> Create a field table and reffers to the pre-created serial.

You could and should create a field of (pseudo-)type 'serial' and be
done with it.

>
> Now I noticed that it is possible to use the default value. I am almost
> quite sure that this is an alternative way and non polite.


The old and still working way to create a field that would function as
surrogate key is to create a sequence, create a field in the table, mark
it integer and set its default value to be the 'nextval' of the created
sequence. That was too much typing for some (I'm included) and later a
syntax sugar was added - the pseudo-type 'serial'.

So the following syntax:

CREATE TABLE example (
   example_sid SERIAL NOT NULL PRIMARY KEY,
   ...
)

is equivalen to:


CREATE SEQUENCE example_example_sid_seq;

CREATE TABLE example (
   example_sid INTEGER PRIMARY KEY DEFAULT
NEXVAL)('example_example_sid_seq'),
   ...
)


As you could see - very convenient for the 99.9% of the cases.

>
> I would like to know if I am correct and what does it means:
>
> nextval('mySerial_id'::regclass)
>
> What is regclass ?

Read here about 'regclass' (there is a note about it) -
http://www.postgresql.org/docs/8.2/static/functions-sequence.html, but
that should not be important to you.


--
Milen A. Radev


---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org





--
Ezequias Rodrigues da Rocha
http://ezequiasrocha.blogspot.com/
use Mozilla Firefox:http://br.mozdev.org/firefox/


[SQL] There is acid without transactions ?

2007-03-11 Thread Ezequias Rodrigues da Rocha

Hi list,

I would like to know if an statement like.

Insert into foo values (1,'Brazil');

Makes an ACID transaction. I am wondered if i must have a  Begin...Commit
statemnt to garantee my ACIDs transactions.

Regards ,

--
Ezequias Rodrigues da Rocha
http://ezequiasrocha.blogspot.com/
use Mozilla Firefox:http://br.mozdev.org/firefox/


Re: [SQL] There is acid without transactions ?

2007-03-11 Thread Jonah H. Harris

On 3/11/07, Ezequias Rodrigues da Rocha <[EMAIL PROTECTED]> wrote:

Insert into foo values (1,'Brazil');


Assuming you're in psql or using the drivers in autocommit mode, then
yes, it's ACID compliant.  Individual statements are treated as an
implicit transaction unless you create an explicit transaction with
BEGIN ... (ROLLBACK | COMMIT).

Some of the drivers, however, will create an explicit transaction
behind-the-scenes if you have autocommit mode disabled.

Did that help or was it more confusing?

--
Jonah H. Harris, Software Architect | phone: 732.331.1324
EnterpriseDB Corporation| fax: 732.331.1301
33 Wood Ave S, 3rd Floor| [EMAIL PROTECTED]
Iselin, New Jersey 08830| http://www.enterprisedb.com/

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [SQL] There is acid without transactions ?

2007-03-11 Thread Ezequias Rodrigues da Rocha

Perfect. I just don't know what drivers you are talking about (odbc maybe).

More perfect is becouse you answare me in only 1 minute. What community
don't is ?

Ezequias

2007/3/11, Jonah H. Harris <[EMAIL PROTECTED]>:


On 3/11/07, Ezequias Rodrigues da Rocha <[EMAIL PROTECTED]> wrote:
> Insert into foo values (1,'Brazil');

Assuming you're in psql or using the drivers in autocommit mode, then
yes, it's ACID compliant.  Individual statements are treated as an
implicit transaction unless you create an explicit transaction with
BEGIN ... (ROLLBACK | COMIT).

Some of the drivers, however, will create an explicit transaction
behind-the-scenes if you have autocommit mode disabled.

Did that help or was it more confusing?

--
Jonah H. Harris, Software Architect | phone: 732.331.1324
EnterpriseDB Corporation| fax: 732.331.1301
33 Wood Ave S, 3rd Floor| [EMAIL PROTECTED]
Iselin, New Jersey 08830| http://www.enterprisedb.com/





--
Ezequias Rodrigues da Rocha
http://ezequiasrocha.blogspot.com/
use Mozilla Firefox:http://br.mozdev.org/firefox/


Re: [SQL] There is acid without transactions ?

2007-03-11 Thread Michael Fuhr
On Sun, Mar 11, 2007 at 01:05:12PM -0300, Ezequias Rodrigues da Rocha wrote:
> I would like to know if an statement like.
> 
> Insert into foo values (1,'Brazil');
> 
> Makes an ACID transaction. I am wondered if i must have a  Begin...Commit
> statemnt to garantee my ACIDs transactions.

http://www.postgresql.org/docs/8.2/interactive/tutorial-transactions.html

"PostgreSQL actually treats every SQL statement as being executed
within a transaction.  If you do not issue a BEGIN command, then
each individual statement has an implicit BEGIN and (if successful)
COMMIT wrapped around it."

-- 
Michael Fuhr

---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate


Re: [SQL] There is acid without transactions ?

2007-03-11 Thread Ezequias Rodrigues da Rocha

Sorry my mistake it was 32 minutes. I am confusing with gmail here.

Anyway today is sunday and it is more difficult to have a reply from
community. Anyway thanks.

Ezequias

2007/3/11, Ezequias Rodrigues da Rocha <[EMAIL PROTECTED]>:


Perfect. I just don't know what drivers you are talking about (odbc
maybe).

More perfect is becouse you answare me in only 1 minute. What community
don't is ?

Ezequias

2007/3/11, Jonah H. Harris <[EMAIL PROTECTED]>:
>
> On 3/11/07, Ezequias Rodrigues da Rocha <[EMAIL PROTECTED]>
> wrote:
> > Insert into foo values (1,'Brazil');
>
> Assuming you're in psql or using the drivers in autocommit mode, then
> yes, it's ACID compliant.  Individual statements are treated as an
> implicit transaction unless you create an explicit transaction with
> BEGIN ... (ROLLBACK | COMIT).
>
> Some of the drivers, however, will create an explicit transaction
> behind-the-scenes if you have autocommit mode disabled.
>
> Did that help or was it more confusing?
>
> --
> Jonah H. Harris, Software Architect | phone: 732.331.1324
> EnterpriseDB Corporation| fax: 732.331.1301
> 33 Wood Ave S, 3rd Floor| [EMAIL PROTECTED]
> Iselin, New Jersey 08830| http://www.enterprisedb.com/
>



--
Ezequias Rodrigues da Rocha
http://ezequiasrocha.blogspot.com/
use Mozilla Firefox: http://br.mozdev.org/firefox/





--
Ezequias Rodrigues da Rocha
http://ezequiasrocha.blogspot.com/
use Mozilla Firefox:http://br.mozdev.org/firefox/


Re: [SQL] Alternative Serial

2007-03-11 Thread A. Kretschmer
am  Sun, dem 11.03.2007, um 11:20:33 -0300 mailte Ezequias Rodrigues da Rocha 
folgendes:
> nextval('mySerial_id'::regclass)
> 
> What is regclass ?

An Object Identifier for relation names.

See http://www.postgresql.org/docs/8.1/interactive/datatype-oid.html


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [SQL] There is acid without transactions ?

2007-03-11 Thread Jonah H. Harris

On 3/11/07, Ezequias Rodrigues da Rocha <[EMAIL PROTECTED]> wrote:

Perfect. I just don't know what drivers you are talking about (odbc maybe).


As the server no longer supports server-side autocommit, I believe all
of the drivers create an explicit transaction behind the scenes when
the user requests autocommit to be turned off.  That way, the drivers
can allow the user to control the transaction state.

The only mainstream driver I know of which doesn't act this way is
libpq, where there is no way to turn off "autocommit" unless you
explicitly create the transaction yourself with BEGIN.

However, I'm sure each of the driver authors will correct me if I'm wrong :)

--
Jonah H. Harris, Software Architect | phone: 732.331.1324
EnterpriseDB Corporation| fax: 732.331.1301
33 Wood Ave S, 3rd Floor| [EMAIL PROTECTED]
Iselin, New Jersey 08830| http://www.enterprisedb.com/

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly