473,289 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

SERIAL type - auto-increment grouped by other field

hi all,

I have problem with SERIAL field type (or sequence functionality).
I have table with three columns - ID, IDS, NAME.
I want auto-increment IDS grouped by ID.
Example:
1, 1, Ferdo
1, 2, John
2, 1, Martin
1, 3, Elvira
2, 2, Georgia

but...
when I use IDS - SERIAL and when I create UNIQUE (ID, IDS) result is:
1, 1, Ferdo
1, 2, John
2, 3, Martin
1, 4, Elvira
2, 5, Georgia

where i make misstake??? how can i do it??? in documentation there is
description only for one auto-increment column. I didn't find auto increment as
I described upper. Do you have any idea how can I do it???

tnx a lot
________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #1
5 5120
Paulovič Michal wrote:
hi all,

I have problem with SERIAL field type (or sequence functionality).
I have table with three columns - ID, IDS, NAME.
I want auto-increment IDS grouped by ID.
Example:
1, 1, Ferdo
1, 2, John
2, 1, Martin
1, 3, Elvira
2, 2, Georgia

but...
when I use IDS - SERIAL and when I create UNIQUE (ID, IDS) result is:
1, 1, Ferdo
1, 2, John
2, 3, Martin
1, 4, Elvira
2, 5, Georgia

where i make misstake??? how can i do it??? in documentation there is
description only for one auto-increment column. I didn't find auto increment as
I described upper. Do you have any idea how can I do it???

tnx a lot

A sequence (which is what a serial is) does not promise you consecutive
numbers. For example - try out the following:
begin a transaction
insert a new row to your table
rollback the transaction

Now add a new row. You will see that the new row did not get the number
that was assigned inside the transaction. All a sequence promises you is
uniqueness (within the 2^32 limit), and that promise is kept for your
example as well.

I can think of something that may help you out here, but you will have
to tell in advance how many groups you will need (how many IDs). Just
create that many sequences and put the id into the sequence name. Then
put in a default value based on that.

--
Shachar Shemesh
Lingnu Open Systems Consulting
http://www.lingnu.com/
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #2
One possible implementation of a two level numbering outline
will be published in PostgreSQL GeneralBits Issue #64 due
out Monday morning, 3/1. http://www.varlena.com/GeneralBits/

elein
================================================== ==========
el***@varlena.com Varlena, LLC www.varlena.com
1-866-VARLENA
PostgreSQL Consulting, Support & Training

PostgreSQL General Bits http://www.varlena.com/GeneralBits/
================================================== ===========
Its a doggy dog world out there.
On Sun, Feb 29, 2004 at 02:44:01AM +0100, Paulovi? Michal wrote:
hi all,

I have problem with SERIAL field type (or sequence functionality).
I have table with three columns - ID, IDS, NAME.
I want auto-increment IDS grouped by ID.
Example:
1, 1, Ferdo
1, 2, John
2, 1, Martin
1, 3, Elvira
2, 2, Georgia

but...
when I use IDS - SERIAL and when I create UNIQUE (ID, IDS) result is:
1, 1, Ferdo
1, 2, John
2, 3, Martin
1, 4, Elvira
2, 5, Georgia

where i make misstake??? how can i do it??? in documentation there is
description only for one auto-increment column. I didn't find auto increment as
I described upper. Do you have any idea how can I do it???

tnx a lot
________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #3
tnx a lot,

but i am using PostgreSQL 7.1.2 and your script result errors:
-------
ERROR: Unrecognized language specified in a CREATE FUNCTION: 'plpgsql'.
Recognized languages are sql, C, internal, and created procedural languages.
-------

elein wrote:
One possible implementation of a two level numbering outline
will be published in PostgreSQL GeneralBits Issue #64 due
out Monday morning, 3/1. http://www.varlena.com/GeneralBits/

elein
================================================= ===========
el***@varlena.com Varlena, LLC www.varlena.com
1-866-VARLENA
PostgreSQL Consulting, Support & Training

PostgreSQL General Bits http://www.varlena.com/GeneralBits/
================================================= ============
Its a doggy dog world out there.
On Sun, Feb 29, 2004 at 02:44:01AM +0100, Paulovi? Michal wrote:

hi all,

I have problem with SERIAL field type (or sequence functionality).
I have table with three columns - ID, IDS, NAME.
I want auto-increment IDS grouped by ID.
Example:
1, 1, Ferdo
1, 2, John
2, 1, Martin
1, 3, Elvira
2, 2, Georgia

but...
when I use IDS - SERIAL and when I create UNIQUE (ID, IDS) result is:
1, 1, Ferdo
1, 2, John
2, 3, Martin
1, 4, Elvira
2, 5, Georgia

where i make misstake??? how can i do it??? in documentation there is
description only for one auto-increment column. I didn't find auto increment as
I described upper. Do you have any idea how can I do it???

tnx a lot
________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #4
You just need to define 'plpgsql' as a language in
your database. At the shell, to define the language use:

createlang 'plpgsql' <dbname>;

After you do the createlang, you can write functions
using plpgsql.

Let me know if you are still having trouble.

--elein

On Mon, Mar 01, 2004 at 09:52:33PM +0100, Paulovi?? Michal wrote:
tnx a lot,

but i am using PostgreSQL 7.1.2 and your script result errors:
-------
ERROR: Unrecognized language specified in a CREATE FUNCTION: 'plpgsql'.
Recognized languages are sql, C, internal, and created procedural languages.
-------

elein wrote:
One possible implementation of a two level numbering outline
will be published in PostgreSQL GeneralBits Issue #64 due
out Monday morning, 3/1. http://www.varlena.com/GeneralBits/

elein
================================================= ===========
el***@varlena.com Varlena, LLC www.varlena.com
1-866-VARLENA
PostgreSQL Consulting, Support & Training

PostgreSQL General Bits http://www.varlena.com/GeneralBits/
================================================= ============
Its a doggy dog world out there.
On Sun, Feb 29, 2004 at 02:44:01AM +0100, Paulovi? Michal wrote:
>hi all,
>
>I have problem with SERIAL field type (or sequence functionality).
>I have table with three columns - ID, IDS, NAME.
>I want auto-increment IDS grouped by ID.
>Example:
>1, 1, Ferdo
>1, 2, John
>2, 1, Martin
>1, 3, Elvira
>2, 2, Georgia
>
>but...
>when I use IDS - SERIAL and when I create UNIQUE (ID, IDS) result is:
>1, 1, Ferdo
>1, 2, John
>2, 3, Martin
>1, 4, Elvira
>2, 5, Georgia
>
>where i make misstake??? how can i do it??? in documentation there is
>description only for one auto-increment column. I didn't find auto
>increment as
>I described upper. Do you have any idea how can I do it???
>
>tnx a lot
>
>
>________ Information from NOD32 ________
>This message was checked by NOD32 Antivirus System for Linux Mail Server.
>http://www.nod32.com
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to ma*******@postgresql.org)
>
>
________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #5
:((

sorry
At server ther is istalled pgsql 7.1.2 but creatlang works from 7.2.X
and upper version :(

do you have any other ideas??

elein wrote:
You just need to define 'plpgsql' as a language in
your database. At the shell, to define the language use:

createlang 'plpgsql' <dbname>;

After you do the createlang, you can write functions
using plpgsql.

Let me know if you are still having trouble.

--elein

On Mon, Mar 01, 2004 at 09:52:33PM +0100, Paulovi?? Michal wrote:

tnx a lot,

but i am using PostgreSQL 7.1.2 and your script result errors:
-------
ERROR: Unrecognized language specified in a CREATE FUNCTION: 'plpgsql'.
Recognized languages are sql, C, internal, and created procedural languages.
-------

elein wrote:

One possible implementation of a two level numbering outline
will be published in PostgreSQL GeneralBits Issue #64 due
out Monday morning, 3/1. http://www.varlena.com/GeneralBits/

elein
============================================== ==============
el***@varlena.com Varlena, LLC www.varlena.com
1-866-VARLENA
PostgreSQL Consulting, Support & Training

PostgreSQL General Bits http://www.varlena.com/GeneralBits/
============================================== ===============
Its a doggy dog world out there.
On Sun, Feb 29, 2004 at 02:44:01AM +0100, Paulovi? Michal wrote:


>hi all,
>
>I have problem with SERIAL field type (or sequence functionality).
>I have table with three columns - ID, IDS, NAME.
>I want auto-increment IDS grouped by ID.
>Example:
>1, 1, Ferdo
>1, 2, John
>2, 1, Martin
>1, 3, Elvira
>2, 2, Georgia
>
>but...
>when I use IDS - SERIAL and when I create UNIQUE (ID, IDS) result is:
>1, 1, Ferdo
>1, 2, John
>2, 3, Martin
>1, 4, Elvira
>2, 5, Georgia
>
>where i make misstake??? how can i do it??? in documentation there is
>description only for one auto-increment column. I didn't find auto
>increment as
>I described upper. Do you have any idea how can I do it???
>
>tnx a lot
>
>
>________ Information from NOD32 ________
>This message was checked by NOD32 Antivirus System for Linux Mail Server.
>http://www.nod32.com
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to ma*******@postgresql.org)
>
>
>
>
________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com



---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org
________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com

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

http://archives.postgresql.org

Nov 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Gavin | last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other groups in a hope to get a response from anyone. Can any one tell me how to make my VB program read the Bios serial number...
2
by: | last post by:
Hi every one I try to get hard disk serial number how can i do this ? -> THANK'S A LOT
5
by: | last post by:
Hi, Do memory sticks have serial numbers like harddrives? If so how can I get this, I want to uniquely identify a memory stick (removable drive) for authentication. Thanks
21
by: nephish | last post by:
i have an interesting project at work going on. here is the challenge. i am using the serial module to read data from a serial input. it comes in as a hex. i need to make it a binary and compare it...
2
by: Techie | last post by:
If I want to create a table with a triggter to retrive data fast in DB2 database, how can I do that? I know in informix we have serial as a data type. what is the equivalent in DB2? what is the...
1
by: Bill Menees | last post by:
VS.NET 2003 defaults the "Debugger Type" property to "Auto" for Visual C++ projects. Unfortunately, the "Auto" type isn't very smart. "Auto" bases the debugger type on the launched EXE's type,...
12
by: Prabu Subroto | last post by:
Dear my friends... I am using postgres 7.4 and SuSE 9.1. I want to use auto_increment as on MySQL. I look up the documentation on www.postgres.com and I found "serial" . But I don't know...
2
by: evle | last post by:
haw to read data from an Infrared Infrared Remote Control
5
by: John J. Hughes II | last post by:
I have a application which opens the port using .NET 2 serial port handler. On my computer using WinXP Pro SP2 updated I have three accounts. On two of the accounts the program is able to open...
6
by: terry | last post by:
Hi, I am trying to send a character to '/dev/ttyS0' and expect the same character and upon receipt I want to send another character. I tired with Pyserial but in vain. Test Set up: 1. Send...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.