Dalton Calford wrote:

This is probably a newbie question but I have never before tried this particular trick. (I always use surrogate keys, go figure)

I have a table where I want to update a specific row returned from a query, but, the only guaranteed unique identifier happens to the dbkey. This is for a one-time process that I wish to perform in PSQL.

for example:

for select FOO, RDB$DB_KEY from YAK into :var_foo, :var_yak
do
begin
  [do some work]
  update YAK set Foo=:var_work where RDB$DB_KEY=:var_yak;
end

I need to know what type of variable :var_yak needs to be defined as.

I could also use a cursor and current type syntax but I have not been able to find example code for this.

Thomas Steinmaurer answers:

Helen Borrie answers:

Actually, the cursor syntax uses the rdb$db_key to determine WHERE CURRENT position anyway. No variables: the loop knows where it is...

The old syntax (pre Fb 2)

for select FOO from YAK
FOR UPDATE
  into :var_foo, :var_yak
AS CURSOR aCursor
do begin
  [do some work]
  update YAK set Foo=:var_work
  where current of aCursor ;
end

If you're on Fb 2 or higher, you'll already be aware of the PSQL cursor enhancements that came with v.2....

Like this post? Share on: TwitterFacebookEmail


Related Articles


Author

Firebird Community

Published

Category

Gems from Firebird Support list

Tags