dbTalk Databases Forums  

Question about firebird!

comp.databases comp.databases


Discuss Question about firebird! in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
db.geek
 
Posts: n/a

Default Question about firebird! - 05-05-2008 , 09:26 AM







CREATE TABLE XX ( ID_ INTEGER NOT NULL,
XXN_ VARCHAR(20),
XXK_ VARCHAR(30) );

I want to insert data into table XX, if has ID_ then update XXN_ and
XXK_ else insert a new row.


How to do this?
Thanks!

--


Reply With Quote
  #2  
Old   
Robert Klemme
 
Posts: n/a

Default Re: Question about firebird! - 05-05-2008 , 10:43 AM






On 05.05.2008 16:26, db.geek wrote:
Quote:
CREATE TABLE XX ( ID_ INTEGER NOT NULL,
XXN_ VARCHAR(20),
XXK_ VARCHAR(30) );

I want to insert data into table XX, if has ID_ then update XXN_ and
XXK_ else insert a new row.

How to do this?
How come a db.geek doesn't know?

Basically you have two options:

1. insert, catch error and update

2. update, check update row count and insert if 0

Which of the two you choose depends on the RDBMS used as well as your
expected distribution of data. IOW if you expect that most data sets
will lead to an insert do approach 1 otherwise do 2.

Also, there can be subtle issues with concurrent updates in scenario 2,
i.e. the update can return 0 rows and the insert can still fail.

Btw, why the strange naming of columns?

Cheers

robert


Reply With Quote
  #3  
Old   
Robert Klemme
 
Posts: n/a

Default Re: Question about firebird! - 05-05-2008 , 10:43 AM



On 05.05.2008 16:26, db.geek wrote:
Quote:
CREATE TABLE XX ( ID_ INTEGER NOT NULL,
XXN_ VARCHAR(20),
XXK_ VARCHAR(30) );

I want to insert data into table XX, if has ID_ then update XXN_ and
XXK_ else insert a new row.

How to do this?
How come a db.geek doesn't know?

Basically you have two options:

1. insert, catch error and update

2. update, check update row count and insert if 0

Which of the two you choose depends on the RDBMS used as well as your
expected distribution of data. IOW if you expect that most data sets
will lead to an insert do approach 1 otherwise do 2.

Also, there can be subtle issues with concurrent updates in scenario 2,
i.e. the update can return 0 rows and the insert can still fail.

Btw, why the strange naming of columns?

Cheers

robert


Reply With Quote
  #4  
Old   
Robert Klemme
 
Posts: n/a

Default Re: Question about firebird! - 05-05-2008 , 10:43 AM



On 05.05.2008 16:26, db.geek wrote:
Quote:
CREATE TABLE XX ( ID_ INTEGER NOT NULL,
XXN_ VARCHAR(20),
XXK_ VARCHAR(30) );

I want to insert data into table XX, if has ID_ then update XXN_ and
XXK_ else insert a new row.

How to do this?
How come a db.geek doesn't know?

Basically you have two options:

1. insert, catch error and update

2. update, check update row count and insert if 0

Which of the two you choose depends on the RDBMS used as well as your
expected distribution of data. IOW if you expect that most data sets
will lead to an insert do approach 1 otherwise do 2.

Also, there can be subtle issues with concurrent updates in scenario 2,
i.e. the update can return 0 rows and the insert can still fail.

Btw, why the strange naming of columns?

Cheers

robert


Reply With Quote
  #5  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: Question about firebird! - 05-05-2008 , 11:10 AM



db.geek, 05.05.2008 16:26:
Quote:
CREATE TABLE XX ( ID_ INTEGER NOT NULL,
XXN_ VARCHAR(20),
XXK_ VARCHAR(30) );

I want to insert data into table XX, if has ID_ then update XXN_ and
XXK_ else insert a new row.


How to do this?
Thanks!

Firebird 2.1 has a MERGE statement which is what you want.
I think 2.0 already had an UPDATE OR INSERT statement.

Thomas


Reply With Quote
  #6  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: Question about firebird! - 05-05-2008 , 11:10 AM



db.geek, 05.05.2008 16:26:
Quote:
CREATE TABLE XX ( ID_ INTEGER NOT NULL,
XXN_ VARCHAR(20),
XXK_ VARCHAR(30) );

I want to insert data into table XX, if has ID_ then update XXN_ and
XXK_ else insert a new row.


How to do this?
Thanks!

Firebird 2.1 has a MERGE statement which is what you want.
I think 2.0 already had an UPDATE OR INSERT statement.

Thomas


Reply With Quote
  #7  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: Question about firebird! - 05-05-2008 , 11:10 AM



db.geek, 05.05.2008 16:26:
Quote:
CREATE TABLE XX ( ID_ INTEGER NOT NULL,
XXN_ VARCHAR(20),
XXK_ VARCHAR(30) );

I want to insert data into table XX, if has ID_ then update XXN_ and
XXK_ else insert a new row.


How to do this?
Thanks!

Firebird 2.1 has a MERGE statement which is what you want.
I think 2.0 already had an UPDATE OR INSERT statement.

Thomas


Reply With Quote
  #8  
Old   
db
 
Posts: n/a

Default Re: Question about firebird! - 05-06-2008 , 07:40 PM



[newblue@bEyoOo ~]$ cat Robert Klemme

Quote:
How come a db.geek doesn't know?
-_-

I'm a db beginner, I hope be come a db geek.

Quote:
Basically you have two options:

1. insert, catch error and update

2. update, check update row count and insert if 0
Now, I'm do it with this way. I post this topic, it is want to look for
a way better than this way, do it fast.

Quote:
Which of the two you choose depends on the RDBMS used as well as your
expected distribution of data. IOW if you expect that most data sets
will lead to an insert do approach 1 otherwise do 2.

Also, there can be subtle issues with concurrent updates in scenario
2, i.e. the update can return 0 rows and the insert can still fail.

Btw, why the strange naming of columns?

Cheers

robert
--
»úÆ÷ÖØÐ¿ª¶¯£¬ÏµÍ³ÖØÐ°²×°£¬½¨Á¢ÐµÄ˼Ï룬Ó*½ÓÐ嵀 ¾ÖÃæ£¬Ò»ÇÐÖØÐÂÔÙÀ´
Èê²»¿ÉÒòÄѶøÍý×Ô±¡·Æ


Reply With Quote
  #9  
Old   
db
 
Posts: n/a

Default Re: Question about firebird! - 05-06-2008 , 07:40 PM



[newblue@bEyoOo ~]$ cat Robert Klemme

Quote:
How come a db.geek doesn't know?
-_-

I'm a db beginner, I hope be come a db geek.

Quote:
Basically you have two options:

1. insert, catch error and update

2. update, check update row count and insert if 0
Now, I'm do it with this way. I post this topic, it is want to look for
a way better than this way, do it fast.

Quote:
Which of the two you choose depends on the RDBMS used as well as your
expected distribution of data. IOW if you expect that most data sets
will lead to an insert do approach 1 otherwise do 2.

Also, there can be subtle issues with concurrent updates in scenario
2, i.e. the update can return 0 rows and the insert can still fail.

Btw, why the strange naming of columns?

Cheers

robert
--
»úÆ÷ÖØÐ¿ª¶¯£¬ÏµÍ³ÖØÐ°²×°£¬½¨Á¢ÐµÄ˼Ï룬Ó*½ÓÐ嵀 ¾ÖÃæ£¬Ò»ÇÐÖØÐÂÔÙÀ´
Èê²»¿ÉÒòÄѶøÍý×Ô±¡·Æ


Reply With Quote
  #10  
Old   
db
 
Posts: n/a

Default Re: Question about firebird! - 05-06-2008 , 07:40 PM



[newblue@bEyoOo ~]$ cat Robert Klemme

Quote:
How come a db.geek doesn't know?
-_-

I'm a db beginner, I hope be come a db geek.

Quote:
Basically you have two options:

1. insert, catch error and update

2. update, check update row count and insert if 0
Now, I'm do it with this way. I post this topic, it is want to look for
a way better than this way, do it fast.

Quote:
Which of the two you choose depends on the RDBMS used as well as your
expected distribution of data. IOW if you expect that most data sets
will lead to an insert do approach 1 otherwise do 2.

Also, there can be subtle issues with concurrent updates in scenario
2, i.e. the update can return 0 rows and the insert can still fail.

Btw, why the strange naming of columns?

Cheers

robert
--
»úÆ÷ÖØÐ¿ª¶¯£¬ÏµÍ³ÖØÐ°²×°£¬½¨Á¢ÐµÄ˼Ï룬Ó*½ÓÐ嵀 ¾ÖÃæ£¬Ò»ÇÐÖØÐÂÔÙÀ´
Èê²»¿ÉÒòÄѶøÍý×Ô±¡·Æ


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.