Updating Firebird BLOB field appending text The Next CEO of Stack OverflowHow can I measure the amount of space taken by blobs on a Firebird 2.1 database?Compact Firebird 2.1 DatabaseHowto update duplicates in firebird?Size of a blob field in FirebirdSplitting firebird database filesInserting large text into blobHungarian characters in Firebird databaseSimple Firebird query very slowJava JDBC type conversion (Firebird / Jaybird): check value/type compatibility before using getter or updater ResultSet method?How do I convert from BLOB SUB_TYPE 0 to TEXT in MySQL?
If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?
What was the first Unix version to run on a microcomputer?
Is it my responsibility to learn a new technology in my own time my employer wants to implement?
Bold, vivid family
What connection does MS Office have to Netscape Navigator?
Are there any unintended negative consequences to allowing PCs to gain multiple levels at once in a short milestone-XP game?
Is HostGator storing my password in plaintext?
Is it possible to search for a directory/file combination?
Should I tutor a student who I know has cheated on their homework?
Between two walls
Inappropriate reference requests from Journal reviewers
Does it take more energy to get to Venus or to Mars?
Interfacing a button to MCU (and PC) with 50m long cable
How do I go from 300 unfinished/half written blog posts, to published posts?
Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?
Novel about a guy who is possessed by the divine essence and the world ends?
Are there any limitations on attacking while grappling?
How do I transpose the 1st and -1th levels of an arbitrarily nested array?
Rotate a column
How to count occurrences of text in a file?
Why am I allowed to create multiple unique pointers from a single object?
How do we know the LHC results are robust?
What benefits would be gained by using human laborers instead of drones in deep sea mining?
What expression will give age in years in QGIS?
Updating Firebird BLOB field appending text
The Next CEO of Stack OverflowHow can I measure the amount of space taken by blobs on a Firebird 2.1 database?Compact Firebird 2.1 DatabaseHowto update duplicates in firebird?Size of a blob field in FirebirdSplitting firebird database filesInserting large text into blobHungarian characters in Firebird databaseSimple Firebird query very slowJava JDBC type conversion (Firebird / Jaybird): check value/type compatibility before using getter or updater ResultSet method?How do I convert from BLOB SUB_TYPE 0 to TEXT in MySQL?
Problem
Can't append text to a blob field, when this value is NULL, using simple concat (||).
Docs base: https://firebirdsql.org/refdocs/langrefupd21-blob.html
Test Env

Assuming types:
- fieldTarget ~ BLOB
- tablePk ~ VARCHAR(5)
Like this:
UPDATE tablename
SET fieldTarget = fieldTarget || :string
WHERE tablePk = :pkTarget;
After execute, no one error returns but the field still null
firebird firebird2.1
add a comment |
Problem
Can't append text to a blob field, when this value is NULL, using simple concat (||).
Docs base: https://firebirdsql.org/refdocs/langrefupd21-blob.html
Test Env

Assuming types:
- fieldTarget ~ BLOB
- tablePk ~ VARCHAR(5)
Like this:
UPDATE tablename
SET fieldTarget = fieldTarget || :string
WHERE tablePk = :pkTarget;
After execute, no one error returns but the field still null
firebird firebird2.1
Are you sure you are actually using Firebird 2.1, is it a dialect 3 database? What is the full type offieldTarget? What happens? Do you get an error? What language and driver are you using? Maybe the problem is that:stringis typed as a blob as well, and your driver doesn't handle this properly?
– Mark Rotteveel
Mar 7 at 20:31
2
Somehow I have repeatedly read over "when this value is NULL"... any operation on null yields null.
– Mark Rotteveel
Mar 8 at 17:21
add a comment |
Problem
Can't append text to a blob field, when this value is NULL, using simple concat (||).
Docs base: https://firebirdsql.org/refdocs/langrefupd21-blob.html
Test Env

Assuming types:
- fieldTarget ~ BLOB
- tablePk ~ VARCHAR(5)
Like this:
UPDATE tablename
SET fieldTarget = fieldTarget || :string
WHERE tablePk = :pkTarget;
After execute, no one error returns but the field still null
firebird firebird2.1
Problem
Can't append text to a blob field, when this value is NULL, using simple concat (||).
Docs base: https://firebirdsql.org/refdocs/langrefupd21-blob.html
Test Env

Assuming types:
- fieldTarget ~ BLOB
- tablePk ~ VARCHAR(5)
Like this:
UPDATE tablename
SET fieldTarget = fieldTarget || :string
WHERE tablePk = :pkTarget;
After execute, no one error returns but the field still null
firebird firebird2.1
firebird firebird2.1
edited Mar 8 at 17:01
gbragamonte
asked Mar 7 at 15:22
gbragamontegbragamonte
355
355
Are you sure you are actually using Firebird 2.1, is it a dialect 3 database? What is the full type offieldTarget? What happens? Do you get an error? What language and driver are you using? Maybe the problem is that:stringis typed as a blob as well, and your driver doesn't handle this properly?
– Mark Rotteveel
Mar 7 at 20:31
2
Somehow I have repeatedly read over "when this value is NULL"... any operation on null yields null.
– Mark Rotteveel
Mar 8 at 17:21
add a comment |
Are you sure you are actually using Firebird 2.1, is it a dialect 3 database? What is the full type offieldTarget? What happens? Do you get an error? What language and driver are you using? Maybe the problem is that:stringis typed as a blob as well, and your driver doesn't handle this properly?
– Mark Rotteveel
Mar 7 at 20:31
2
Somehow I have repeatedly read over "when this value is NULL"... any operation on null yields null.
– Mark Rotteveel
Mar 8 at 17:21
Are you sure you are actually using Firebird 2.1, is it a dialect 3 database? What is the full type of
fieldTarget? What happens? Do you get an error? What language and driver are you using? Maybe the problem is that :string is typed as a blob as well, and your driver doesn't handle this properly?– Mark Rotteveel
Mar 7 at 20:31
Are you sure you are actually using Firebird 2.1, is it a dialect 3 database? What is the full type of
fieldTarget? What happens? Do you get an error? What language and driver are you using? Maybe the problem is that :string is typed as a blob as well, and your driver doesn't handle this properly?– Mark Rotteveel
Mar 7 at 20:31
2
2
Somehow I have repeatedly read over "when this value is NULL"... any operation on null yields null.
– Mark Rotteveel
Mar 8 at 17:21
Somehow I have repeatedly read over "when this value is NULL"... any operation on null yields null.
– Mark Rotteveel
Mar 8 at 17:21
add a comment |
2 Answers
2
active
oldest
votes
All string operations (like ||-concatenation) are bound by maximum VarChar size limit (which is 32 KBytes, which is less than 8200 letters in UTF-8 encoded text).
However there seems to be BLOB-oriented functions. It also does not need escaping NULL-values with COALESCE.
LIST returns a string consisting of the non-NULL argument values in the group, separated either by a comma or by a user-supplied delimiter
https://firebirdsql.org/refdocs/langrefupd21-aggrfunc-list.html
Hence, using derived tables:
Select LIST(ALL X, '') From
( Select fieldTarget as x From tablename Where tablePk = :pkTarget
UNION ALL
Select Cast( :string AS VarChar(8191) ) From RDB$DATABASE )
As TMP
The typecasting is to assign data-type to the parameter-only expression.
P.S. the documentation also claims that
The ordering of the list values is undefined.
P.P.S. Ready to run example, tested on FB 2.1.7
Select LIST(ALL X, '') From
( Select Cast( :str_pre AS VarChar(8191) ) as X From RDB$DATABASE
UNION ALL
Select /* DATA column */ RDB$TRIGGER_SOURCE
From /* DATA table */ RDB$TRIGGERS
Where /* PK ID */ RDB$TRIGGER_NAME = :pkTarget
UNION ALL
Select Cast( :str_post AS VarChar(8191) ) From RDB$DATABASE
)
Passing names like RDB$TRIGGER_1 would give you a system trigger that has no source text, thus has a NULL value in the field. Easy to check that you need no COALESCE-screening here :-D
Since Firebird 2.1, concatenation (||) supports (text) blobs, there should be no need for magic. See firebirdsql.org/refdocs/langrefupd25-concat.html
– Mark Rotteveel
Mar 7 at 20:29
@MarkRotteveel but with two limitations: NULL-values are not skipped but result in NULL result, and only small VARCHAR-sized BLOBs can use it (IOW it is not extansion of operators to BLOBs but implicit typecasting BLOB-into-VARCHAR). See firebirdsql.org/file/documentation/release_notes/html/… "(v.2.1) At various levels of evaluation, the engine now treats text BLOBs that are within the 32,765-byte string size limit as though they were VARCHARs. Operations that now allow text BLOBs to behave like strings are: Assignments, conversions and concatenations (|| operator)"
– Arioch 'The
Mar 7 at 23:19
Well, that is explicitly stated in the summary / table of contents: "“Short” BLOBs Can Masquerade as Long VARCHARs" :-D // Oh, the 3rd limitations: only sub_type-text BLOBs are going this way, not default "binary" BLOBs. Which, perhaps, makes sense, minding charset problems
– Arioch 'The
Mar 7 at 23:21
I haven't rechecked 2.1, but in more recent versions there is no such limit that I'm aware. Blob concatenation will work for text blobs of any length (and so does substring and others); I haven't checked binary blobs. The null-behavior you mention is standard, and would also apply to varchar concatenation.
– Mark Rotteveel
Mar 8 at 16:15
This NULL behaviour is standard, of course, but is not what the topic-starter wanted, judging by both his question and use of COALESCE in his own now deleted answer. @MarkRotteveel
– Arioch 'The
Mar 9 at 12:25
add a comment |
The primary problem you are having is that the original value is NULL. Operations like addition, concatenation, etc on a NULL value will yield NULL. For a deep-dive into the details of NULL, consider reading the Firebird Null Guide.
The solution is to use COALESCE to provide a default (eg empty string) when the column is null*.
UPDATE tablename
SET fieldTarget = COALESCE(fieldTarget, '') || :string
WHERE tablePk = :pkTarget;
*: you already had this in your now deleted answer, but it was a bit obscured by the casts to varchar which shouldn't be necessary
i already tryed this way but returns this error:SQL Error [335544454] [HY000]: filter not found to convert type 1 to type 2 [SQLState:HY000, ISC error code:335544454]
– gbragamonte
Mar 8 at 17:48
@gbragamonte That would mean the field is not a text blob (aka sub_type 1), but a blob sub_type 2 (BLR) which should be used for Firebird internal purposes only (and you shouldn't even be able to define blobs of that type, but I'm not sure if that protection already existed in Firebird 2.1).
– Mark Rotteveel
Mar 8 at 20:56
@gbragamonte You may want to fix the issue and recreating the blob as one of the right type, or if you think it already is a blob sub_type text (or sub_type 1), then it would be really helpful to have a fully reproducible example.
– Mark Rotteveel
Mar 8 at 20:58
@MarkRotteveel at least in FB2.5 (but i believe in any FB2.x) one can cast BLR-BLOB into VARCHAR, which invokes Firebird's built-in "dis-assembler" to convert "compiled" byte-code into more or less readable mnemonics. It would be weird if BLR blobs can be converted to varchar but not to txt-blob. P.S. maybe it is not the field, but the parameter that somehow gets subtype 2?
– Arioch 'The
Mar 9 at 12:28
1
@Arioch'The The error is about from type 1 to type 2 which would happen on store, not from type 2 to type 1. Also, the way the OP is executing (in DBeaver) will result in the value being incorporated as a literal before execution, so there is no parameter. I could only reproduce it in Firebird 2.1 by manually setting the sub type of the field to 2 (using a system table update as you can't create a type 2 blob using DDL in 2.1).
– Mark Rotteveel
Mar 9 at 13:43
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047256%2fupdating-firebird-blob-field-appending-text%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
All string operations (like ||-concatenation) are bound by maximum VarChar size limit (which is 32 KBytes, which is less than 8200 letters in UTF-8 encoded text).
However there seems to be BLOB-oriented functions. It also does not need escaping NULL-values with COALESCE.
LIST returns a string consisting of the non-NULL argument values in the group, separated either by a comma or by a user-supplied delimiter
https://firebirdsql.org/refdocs/langrefupd21-aggrfunc-list.html
Hence, using derived tables:
Select LIST(ALL X, '') From
( Select fieldTarget as x From tablename Where tablePk = :pkTarget
UNION ALL
Select Cast( :string AS VarChar(8191) ) From RDB$DATABASE )
As TMP
The typecasting is to assign data-type to the parameter-only expression.
P.S. the documentation also claims that
The ordering of the list values is undefined.
P.P.S. Ready to run example, tested on FB 2.1.7
Select LIST(ALL X, '') From
( Select Cast( :str_pre AS VarChar(8191) ) as X From RDB$DATABASE
UNION ALL
Select /* DATA column */ RDB$TRIGGER_SOURCE
From /* DATA table */ RDB$TRIGGERS
Where /* PK ID */ RDB$TRIGGER_NAME = :pkTarget
UNION ALL
Select Cast( :str_post AS VarChar(8191) ) From RDB$DATABASE
)
Passing names like RDB$TRIGGER_1 would give you a system trigger that has no source text, thus has a NULL value in the field. Easy to check that you need no COALESCE-screening here :-D
Since Firebird 2.1, concatenation (||) supports (text) blobs, there should be no need for magic. See firebirdsql.org/refdocs/langrefupd25-concat.html
– Mark Rotteveel
Mar 7 at 20:29
@MarkRotteveel but with two limitations: NULL-values are not skipped but result in NULL result, and only small VARCHAR-sized BLOBs can use it (IOW it is not extansion of operators to BLOBs but implicit typecasting BLOB-into-VARCHAR). See firebirdsql.org/file/documentation/release_notes/html/… "(v.2.1) At various levels of evaluation, the engine now treats text BLOBs that are within the 32,765-byte string size limit as though they were VARCHARs. Operations that now allow text BLOBs to behave like strings are: Assignments, conversions and concatenations (|| operator)"
– Arioch 'The
Mar 7 at 23:19
Well, that is explicitly stated in the summary / table of contents: "“Short” BLOBs Can Masquerade as Long VARCHARs" :-D // Oh, the 3rd limitations: only sub_type-text BLOBs are going this way, not default "binary" BLOBs. Which, perhaps, makes sense, minding charset problems
– Arioch 'The
Mar 7 at 23:21
I haven't rechecked 2.1, but in more recent versions there is no such limit that I'm aware. Blob concatenation will work for text blobs of any length (and so does substring and others); I haven't checked binary blobs. The null-behavior you mention is standard, and would also apply to varchar concatenation.
– Mark Rotteveel
Mar 8 at 16:15
This NULL behaviour is standard, of course, but is not what the topic-starter wanted, judging by both his question and use of COALESCE in his own now deleted answer. @MarkRotteveel
– Arioch 'The
Mar 9 at 12:25
add a comment |
All string operations (like ||-concatenation) are bound by maximum VarChar size limit (which is 32 KBytes, which is less than 8200 letters in UTF-8 encoded text).
However there seems to be BLOB-oriented functions. It also does not need escaping NULL-values with COALESCE.
LIST returns a string consisting of the non-NULL argument values in the group, separated either by a comma or by a user-supplied delimiter
https://firebirdsql.org/refdocs/langrefupd21-aggrfunc-list.html
Hence, using derived tables:
Select LIST(ALL X, '') From
( Select fieldTarget as x From tablename Where tablePk = :pkTarget
UNION ALL
Select Cast( :string AS VarChar(8191) ) From RDB$DATABASE )
As TMP
The typecasting is to assign data-type to the parameter-only expression.
P.S. the documentation also claims that
The ordering of the list values is undefined.
P.P.S. Ready to run example, tested on FB 2.1.7
Select LIST(ALL X, '') From
( Select Cast( :str_pre AS VarChar(8191) ) as X From RDB$DATABASE
UNION ALL
Select /* DATA column */ RDB$TRIGGER_SOURCE
From /* DATA table */ RDB$TRIGGERS
Where /* PK ID */ RDB$TRIGGER_NAME = :pkTarget
UNION ALL
Select Cast( :str_post AS VarChar(8191) ) From RDB$DATABASE
)
Passing names like RDB$TRIGGER_1 would give you a system trigger that has no source text, thus has a NULL value in the field. Easy to check that you need no COALESCE-screening here :-D
Since Firebird 2.1, concatenation (||) supports (text) blobs, there should be no need for magic. See firebirdsql.org/refdocs/langrefupd25-concat.html
– Mark Rotteveel
Mar 7 at 20:29
@MarkRotteveel but with two limitations: NULL-values are not skipped but result in NULL result, and only small VARCHAR-sized BLOBs can use it (IOW it is not extansion of operators to BLOBs but implicit typecasting BLOB-into-VARCHAR). See firebirdsql.org/file/documentation/release_notes/html/… "(v.2.1) At various levels of evaluation, the engine now treats text BLOBs that are within the 32,765-byte string size limit as though they were VARCHARs. Operations that now allow text BLOBs to behave like strings are: Assignments, conversions and concatenations (|| operator)"
– Arioch 'The
Mar 7 at 23:19
Well, that is explicitly stated in the summary / table of contents: "“Short” BLOBs Can Masquerade as Long VARCHARs" :-D // Oh, the 3rd limitations: only sub_type-text BLOBs are going this way, not default "binary" BLOBs. Which, perhaps, makes sense, minding charset problems
– Arioch 'The
Mar 7 at 23:21
I haven't rechecked 2.1, but in more recent versions there is no such limit that I'm aware. Blob concatenation will work for text blobs of any length (and so does substring and others); I haven't checked binary blobs. The null-behavior you mention is standard, and would also apply to varchar concatenation.
– Mark Rotteveel
Mar 8 at 16:15
This NULL behaviour is standard, of course, but is not what the topic-starter wanted, judging by both his question and use of COALESCE in his own now deleted answer. @MarkRotteveel
– Arioch 'The
Mar 9 at 12:25
add a comment |
All string operations (like ||-concatenation) are bound by maximum VarChar size limit (which is 32 KBytes, which is less than 8200 letters in UTF-8 encoded text).
However there seems to be BLOB-oriented functions. It also does not need escaping NULL-values with COALESCE.
LIST returns a string consisting of the non-NULL argument values in the group, separated either by a comma or by a user-supplied delimiter
https://firebirdsql.org/refdocs/langrefupd21-aggrfunc-list.html
Hence, using derived tables:
Select LIST(ALL X, '') From
( Select fieldTarget as x From tablename Where tablePk = :pkTarget
UNION ALL
Select Cast( :string AS VarChar(8191) ) From RDB$DATABASE )
As TMP
The typecasting is to assign data-type to the parameter-only expression.
P.S. the documentation also claims that
The ordering of the list values is undefined.
P.P.S. Ready to run example, tested on FB 2.1.7
Select LIST(ALL X, '') From
( Select Cast( :str_pre AS VarChar(8191) ) as X From RDB$DATABASE
UNION ALL
Select /* DATA column */ RDB$TRIGGER_SOURCE
From /* DATA table */ RDB$TRIGGERS
Where /* PK ID */ RDB$TRIGGER_NAME = :pkTarget
UNION ALL
Select Cast( :str_post AS VarChar(8191) ) From RDB$DATABASE
)
Passing names like RDB$TRIGGER_1 would give you a system trigger that has no source text, thus has a NULL value in the field. Easy to check that you need no COALESCE-screening here :-D
All string operations (like ||-concatenation) are bound by maximum VarChar size limit (which is 32 KBytes, which is less than 8200 letters in UTF-8 encoded text).
However there seems to be BLOB-oriented functions. It also does not need escaping NULL-values with COALESCE.
LIST returns a string consisting of the non-NULL argument values in the group, separated either by a comma or by a user-supplied delimiter
https://firebirdsql.org/refdocs/langrefupd21-aggrfunc-list.html
Hence, using derived tables:
Select LIST(ALL X, '') From
( Select fieldTarget as x From tablename Where tablePk = :pkTarget
UNION ALL
Select Cast( :string AS VarChar(8191) ) From RDB$DATABASE )
As TMP
The typecasting is to assign data-type to the parameter-only expression.
P.S. the documentation also claims that
The ordering of the list values is undefined.
P.P.S. Ready to run example, tested on FB 2.1.7
Select LIST(ALL X, '') From
( Select Cast( :str_pre AS VarChar(8191) ) as X From RDB$DATABASE
UNION ALL
Select /* DATA column */ RDB$TRIGGER_SOURCE
From /* DATA table */ RDB$TRIGGERS
Where /* PK ID */ RDB$TRIGGER_NAME = :pkTarget
UNION ALL
Select Cast( :str_post AS VarChar(8191) ) From RDB$DATABASE
)
Passing names like RDB$TRIGGER_1 would give you a system trigger that has no source text, thus has a NULL value in the field. Easy to check that you need no COALESCE-screening here :-D
edited Mar 7 at 17:32
answered Mar 7 at 17:20
Arioch 'TheArioch 'The
13k1649
13k1649
Since Firebird 2.1, concatenation (||) supports (text) blobs, there should be no need for magic. See firebirdsql.org/refdocs/langrefupd25-concat.html
– Mark Rotteveel
Mar 7 at 20:29
@MarkRotteveel but with two limitations: NULL-values are not skipped but result in NULL result, and only small VARCHAR-sized BLOBs can use it (IOW it is not extansion of operators to BLOBs but implicit typecasting BLOB-into-VARCHAR). See firebirdsql.org/file/documentation/release_notes/html/… "(v.2.1) At various levels of evaluation, the engine now treats text BLOBs that are within the 32,765-byte string size limit as though they were VARCHARs. Operations that now allow text BLOBs to behave like strings are: Assignments, conversions and concatenations (|| operator)"
– Arioch 'The
Mar 7 at 23:19
Well, that is explicitly stated in the summary / table of contents: "“Short” BLOBs Can Masquerade as Long VARCHARs" :-D // Oh, the 3rd limitations: only sub_type-text BLOBs are going this way, not default "binary" BLOBs. Which, perhaps, makes sense, minding charset problems
– Arioch 'The
Mar 7 at 23:21
I haven't rechecked 2.1, but in more recent versions there is no such limit that I'm aware. Blob concatenation will work for text blobs of any length (and so does substring and others); I haven't checked binary blobs. The null-behavior you mention is standard, and would also apply to varchar concatenation.
– Mark Rotteveel
Mar 8 at 16:15
This NULL behaviour is standard, of course, but is not what the topic-starter wanted, judging by both his question and use of COALESCE in his own now deleted answer. @MarkRotteveel
– Arioch 'The
Mar 9 at 12:25
add a comment |
Since Firebird 2.1, concatenation (||) supports (text) blobs, there should be no need for magic. See firebirdsql.org/refdocs/langrefupd25-concat.html
– Mark Rotteveel
Mar 7 at 20:29
@MarkRotteveel but with two limitations: NULL-values are not skipped but result in NULL result, and only small VARCHAR-sized BLOBs can use it (IOW it is not extansion of operators to BLOBs but implicit typecasting BLOB-into-VARCHAR). See firebirdsql.org/file/documentation/release_notes/html/… "(v.2.1) At various levels of evaluation, the engine now treats text BLOBs that are within the 32,765-byte string size limit as though they were VARCHARs. Operations that now allow text BLOBs to behave like strings are: Assignments, conversions and concatenations (|| operator)"
– Arioch 'The
Mar 7 at 23:19
Well, that is explicitly stated in the summary / table of contents: "“Short” BLOBs Can Masquerade as Long VARCHARs" :-D // Oh, the 3rd limitations: only sub_type-text BLOBs are going this way, not default "binary" BLOBs. Which, perhaps, makes sense, minding charset problems
– Arioch 'The
Mar 7 at 23:21
I haven't rechecked 2.1, but in more recent versions there is no such limit that I'm aware. Blob concatenation will work for text blobs of any length (and so does substring and others); I haven't checked binary blobs. The null-behavior you mention is standard, and would also apply to varchar concatenation.
– Mark Rotteveel
Mar 8 at 16:15
This NULL behaviour is standard, of course, but is not what the topic-starter wanted, judging by both his question and use of COALESCE in his own now deleted answer. @MarkRotteveel
– Arioch 'The
Mar 9 at 12:25
Since Firebird 2.1, concatenation (
||) supports (text) blobs, there should be no need for magic. See firebirdsql.org/refdocs/langrefupd25-concat.html– Mark Rotteveel
Mar 7 at 20:29
Since Firebird 2.1, concatenation (
||) supports (text) blobs, there should be no need for magic. See firebirdsql.org/refdocs/langrefupd25-concat.html– Mark Rotteveel
Mar 7 at 20:29
@MarkRotteveel but with two limitations: NULL-values are not skipped but result in NULL result, and only small VARCHAR-sized BLOBs can use it (IOW it is not extansion of operators to BLOBs but implicit typecasting BLOB-into-VARCHAR). See firebirdsql.org/file/documentation/release_notes/html/… "(v.2.1) At various levels of evaluation, the engine now treats text BLOBs that are within the 32,765-byte string size limit as though they were VARCHARs. Operations that now allow text BLOBs to behave like strings are: Assignments, conversions and concatenations (|| operator)"
– Arioch 'The
Mar 7 at 23:19
@MarkRotteveel but with two limitations: NULL-values are not skipped but result in NULL result, and only small VARCHAR-sized BLOBs can use it (IOW it is not extansion of operators to BLOBs but implicit typecasting BLOB-into-VARCHAR). See firebirdsql.org/file/documentation/release_notes/html/… "(v.2.1) At various levels of evaluation, the engine now treats text BLOBs that are within the 32,765-byte string size limit as though they were VARCHARs. Operations that now allow text BLOBs to behave like strings are: Assignments, conversions and concatenations (|| operator)"
– Arioch 'The
Mar 7 at 23:19
Well, that is explicitly stated in the summary / table of contents: "“Short” BLOBs Can Masquerade as Long VARCHARs" :-D // Oh, the 3rd limitations: only sub_type-text BLOBs are going this way, not default "binary" BLOBs. Which, perhaps, makes sense, minding charset problems
– Arioch 'The
Mar 7 at 23:21
Well, that is explicitly stated in the summary / table of contents: "“Short” BLOBs Can Masquerade as Long VARCHARs" :-D // Oh, the 3rd limitations: only sub_type-text BLOBs are going this way, not default "binary" BLOBs. Which, perhaps, makes sense, minding charset problems
– Arioch 'The
Mar 7 at 23:21
I haven't rechecked 2.1, but in more recent versions there is no such limit that I'm aware. Blob concatenation will work for text blobs of any length (and so does substring and others); I haven't checked binary blobs. The null-behavior you mention is standard, and would also apply to varchar concatenation.
– Mark Rotteveel
Mar 8 at 16:15
I haven't rechecked 2.1, but in more recent versions there is no such limit that I'm aware. Blob concatenation will work for text blobs of any length (and so does substring and others); I haven't checked binary blobs. The null-behavior you mention is standard, and would also apply to varchar concatenation.
– Mark Rotteveel
Mar 8 at 16:15
This NULL behaviour is standard, of course, but is not what the topic-starter wanted, judging by both his question and use of COALESCE in his own now deleted answer. @MarkRotteveel
– Arioch 'The
Mar 9 at 12:25
This NULL behaviour is standard, of course, but is not what the topic-starter wanted, judging by both his question and use of COALESCE in his own now deleted answer. @MarkRotteveel
– Arioch 'The
Mar 9 at 12:25
add a comment |
The primary problem you are having is that the original value is NULL. Operations like addition, concatenation, etc on a NULL value will yield NULL. For a deep-dive into the details of NULL, consider reading the Firebird Null Guide.
The solution is to use COALESCE to provide a default (eg empty string) when the column is null*.
UPDATE tablename
SET fieldTarget = COALESCE(fieldTarget, '') || :string
WHERE tablePk = :pkTarget;
*: you already had this in your now deleted answer, but it was a bit obscured by the casts to varchar which shouldn't be necessary
i already tryed this way but returns this error:SQL Error [335544454] [HY000]: filter not found to convert type 1 to type 2 [SQLState:HY000, ISC error code:335544454]
– gbragamonte
Mar 8 at 17:48
@gbragamonte That would mean the field is not a text blob (aka sub_type 1), but a blob sub_type 2 (BLR) which should be used for Firebird internal purposes only (and you shouldn't even be able to define blobs of that type, but I'm not sure if that protection already existed in Firebird 2.1).
– Mark Rotteveel
Mar 8 at 20:56
@gbragamonte You may want to fix the issue and recreating the blob as one of the right type, or if you think it already is a blob sub_type text (or sub_type 1), then it would be really helpful to have a fully reproducible example.
– Mark Rotteveel
Mar 8 at 20:58
@MarkRotteveel at least in FB2.5 (but i believe in any FB2.x) one can cast BLR-BLOB into VARCHAR, which invokes Firebird's built-in "dis-assembler" to convert "compiled" byte-code into more or less readable mnemonics. It would be weird if BLR blobs can be converted to varchar but not to txt-blob. P.S. maybe it is not the field, but the parameter that somehow gets subtype 2?
– Arioch 'The
Mar 9 at 12:28
1
@Arioch'The The error is about from type 1 to type 2 which would happen on store, not from type 2 to type 1. Also, the way the OP is executing (in DBeaver) will result in the value being incorporated as a literal before execution, so there is no parameter. I could only reproduce it in Firebird 2.1 by manually setting the sub type of the field to 2 (using a system table update as you can't create a type 2 blob using DDL in 2.1).
– Mark Rotteveel
Mar 9 at 13:43
|
show 1 more comment
The primary problem you are having is that the original value is NULL. Operations like addition, concatenation, etc on a NULL value will yield NULL. For a deep-dive into the details of NULL, consider reading the Firebird Null Guide.
The solution is to use COALESCE to provide a default (eg empty string) when the column is null*.
UPDATE tablename
SET fieldTarget = COALESCE(fieldTarget, '') || :string
WHERE tablePk = :pkTarget;
*: you already had this in your now deleted answer, but it was a bit obscured by the casts to varchar which shouldn't be necessary
i already tryed this way but returns this error:SQL Error [335544454] [HY000]: filter not found to convert type 1 to type 2 [SQLState:HY000, ISC error code:335544454]
– gbragamonte
Mar 8 at 17:48
@gbragamonte That would mean the field is not a text blob (aka sub_type 1), but a blob sub_type 2 (BLR) which should be used for Firebird internal purposes only (and you shouldn't even be able to define blobs of that type, but I'm not sure if that protection already existed in Firebird 2.1).
– Mark Rotteveel
Mar 8 at 20:56
@gbragamonte You may want to fix the issue and recreating the blob as one of the right type, or if you think it already is a blob sub_type text (or sub_type 1), then it would be really helpful to have a fully reproducible example.
– Mark Rotteveel
Mar 8 at 20:58
@MarkRotteveel at least in FB2.5 (but i believe in any FB2.x) one can cast BLR-BLOB into VARCHAR, which invokes Firebird's built-in "dis-assembler" to convert "compiled" byte-code into more or less readable mnemonics. It would be weird if BLR blobs can be converted to varchar but not to txt-blob. P.S. maybe it is not the field, but the parameter that somehow gets subtype 2?
– Arioch 'The
Mar 9 at 12:28
1
@Arioch'The The error is about from type 1 to type 2 which would happen on store, not from type 2 to type 1. Also, the way the OP is executing (in DBeaver) will result in the value being incorporated as a literal before execution, so there is no parameter. I could only reproduce it in Firebird 2.1 by manually setting the sub type of the field to 2 (using a system table update as you can't create a type 2 blob using DDL in 2.1).
– Mark Rotteveel
Mar 9 at 13:43
|
show 1 more comment
The primary problem you are having is that the original value is NULL. Operations like addition, concatenation, etc on a NULL value will yield NULL. For a deep-dive into the details of NULL, consider reading the Firebird Null Guide.
The solution is to use COALESCE to provide a default (eg empty string) when the column is null*.
UPDATE tablename
SET fieldTarget = COALESCE(fieldTarget, '') || :string
WHERE tablePk = :pkTarget;
*: you already had this in your now deleted answer, but it was a bit obscured by the casts to varchar which shouldn't be necessary
The primary problem you are having is that the original value is NULL. Operations like addition, concatenation, etc on a NULL value will yield NULL. For a deep-dive into the details of NULL, consider reading the Firebird Null Guide.
The solution is to use COALESCE to provide a default (eg empty string) when the column is null*.
UPDATE tablename
SET fieldTarget = COALESCE(fieldTarget, '') || :string
WHERE tablePk = :pkTarget;
*: you already had this in your now deleted answer, but it was a bit obscured by the casts to varchar which shouldn't be necessary
answered Mar 8 at 17:38
community wiki
Mark Rotteveel
i already tryed this way but returns this error:SQL Error [335544454] [HY000]: filter not found to convert type 1 to type 2 [SQLState:HY000, ISC error code:335544454]
– gbragamonte
Mar 8 at 17:48
@gbragamonte That would mean the field is not a text blob (aka sub_type 1), but a blob sub_type 2 (BLR) which should be used for Firebird internal purposes only (and you shouldn't even be able to define blobs of that type, but I'm not sure if that protection already existed in Firebird 2.1).
– Mark Rotteveel
Mar 8 at 20:56
@gbragamonte You may want to fix the issue and recreating the blob as one of the right type, or if you think it already is a blob sub_type text (or sub_type 1), then it would be really helpful to have a fully reproducible example.
– Mark Rotteveel
Mar 8 at 20:58
@MarkRotteveel at least in FB2.5 (but i believe in any FB2.x) one can cast BLR-BLOB into VARCHAR, which invokes Firebird's built-in "dis-assembler" to convert "compiled" byte-code into more or less readable mnemonics. It would be weird if BLR blobs can be converted to varchar but not to txt-blob. P.S. maybe it is not the field, but the parameter that somehow gets subtype 2?
– Arioch 'The
Mar 9 at 12:28
1
@Arioch'The The error is about from type 1 to type 2 which would happen on store, not from type 2 to type 1. Also, the way the OP is executing (in DBeaver) will result in the value being incorporated as a literal before execution, so there is no parameter. I could only reproduce it in Firebird 2.1 by manually setting the sub type of the field to 2 (using a system table update as you can't create a type 2 blob using DDL in 2.1).
– Mark Rotteveel
Mar 9 at 13:43
|
show 1 more comment
i already tryed this way but returns this error:SQL Error [335544454] [HY000]: filter not found to convert type 1 to type 2 [SQLState:HY000, ISC error code:335544454]
– gbragamonte
Mar 8 at 17:48
@gbragamonte That would mean the field is not a text blob (aka sub_type 1), but a blob sub_type 2 (BLR) which should be used for Firebird internal purposes only (and you shouldn't even be able to define blobs of that type, but I'm not sure if that protection already existed in Firebird 2.1).
– Mark Rotteveel
Mar 8 at 20:56
@gbragamonte You may want to fix the issue and recreating the blob as one of the right type, or if you think it already is a blob sub_type text (or sub_type 1), then it would be really helpful to have a fully reproducible example.
– Mark Rotteveel
Mar 8 at 20:58
@MarkRotteveel at least in FB2.5 (but i believe in any FB2.x) one can cast BLR-BLOB into VARCHAR, which invokes Firebird's built-in "dis-assembler" to convert "compiled" byte-code into more or less readable mnemonics. It would be weird if BLR blobs can be converted to varchar but not to txt-blob. P.S. maybe it is not the field, but the parameter that somehow gets subtype 2?
– Arioch 'The
Mar 9 at 12:28
1
@Arioch'The The error is about from type 1 to type 2 which would happen on store, not from type 2 to type 1. Also, the way the OP is executing (in DBeaver) will result in the value being incorporated as a literal before execution, so there is no parameter. I could only reproduce it in Firebird 2.1 by manually setting the sub type of the field to 2 (using a system table update as you can't create a type 2 blob using DDL in 2.1).
– Mark Rotteveel
Mar 9 at 13:43
i already tryed this way but returns this error:
SQL Error [335544454] [HY000]: filter not found to convert type 1 to type 2 [SQLState:HY000, ISC error code:335544454]– gbragamonte
Mar 8 at 17:48
i already tryed this way but returns this error:
SQL Error [335544454] [HY000]: filter not found to convert type 1 to type 2 [SQLState:HY000, ISC error code:335544454]– gbragamonte
Mar 8 at 17:48
@gbragamonte That would mean the field is not a text blob (aka sub_type 1), but a blob sub_type 2 (BLR) which should be used for Firebird internal purposes only (and you shouldn't even be able to define blobs of that type, but I'm not sure if that protection already existed in Firebird 2.1).
– Mark Rotteveel
Mar 8 at 20:56
@gbragamonte That would mean the field is not a text blob (aka sub_type 1), but a blob sub_type 2 (BLR) which should be used for Firebird internal purposes only (and you shouldn't even be able to define blobs of that type, but I'm not sure if that protection already existed in Firebird 2.1).
– Mark Rotteveel
Mar 8 at 20:56
@gbragamonte You may want to fix the issue and recreating the blob as one of the right type, or if you think it already is a blob sub_type text (or sub_type 1), then it would be really helpful to have a fully reproducible example.
– Mark Rotteveel
Mar 8 at 20:58
@gbragamonte You may want to fix the issue and recreating the blob as one of the right type, or if you think it already is a blob sub_type text (or sub_type 1), then it would be really helpful to have a fully reproducible example.
– Mark Rotteveel
Mar 8 at 20:58
@MarkRotteveel at least in FB2.5 (but i believe in any FB2.x) one can cast BLR-BLOB into VARCHAR, which invokes Firebird's built-in "dis-assembler" to convert "compiled" byte-code into more or less readable mnemonics. It would be weird if BLR blobs can be converted to varchar but not to txt-blob. P.S. maybe it is not the field, but the parameter that somehow gets subtype 2?
– Arioch 'The
Mar 9 at 12:28
@MarkRotteveel at least in FB2.5 (but i believe in any FB2.x) one can cast BLR-BLOB into VARCHAR, which invokes Firebird's built-in "dis-assembler" to convert "compiled" byte-code into more or less readable mnemonics. It would be weird if BLR blobs can be converted to varchar but not to txt-blob. P.S. maybe it is not the field, but the parameter that somehow gets subtype 2?
– Arioch 'The
Mar 9 at 12:28
1
1
@Arioch'The The error is about from type 1 to type 2 which would happen on store, not from type 2 to type 1. Also, the way the OP is executing (in DBeaver) will result in the value being incorporated as a literal before execution, so there is no parameter. I could only reproduce it in Firebird 2.1 by manually setting the sub type of the field to 2 (using a system table update as you can't create a type 2 blob using DDL in 2.1).
– Mark Rotteveel
Mar 9 at 13:43
@Arioch'The The error is about from type 1 to type 2 which would happen on store, not from type 2 to type 1. Also, the way the OP is executing (in DBeaver) will result in the value being incorporated as a literal before execution, so there is no parameter. I could only reproduce it in Firebird 2.1 by manually setting the sub type of the field to 2 (using a system table update as you can't create a type 2 blob using DDL in 2.1).
– Mark Rotteveel
Mar 9 at 13:43
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047256%2fupdating-firebird-blob-field-appending-text%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you sure you are actually using Firebird 2.1, is it a dialect 3 database? What is the full type of
fieldTarget? What happens? Do you get an error? What language and driver are you using? Maybe the problem is that:stringis typed as a blob as well, and your driver doesn't handle this properly?– Mark Rotteveel
Mar 7 at 20:31
2
Somehow I have repeatedly read over "when this value is NULL"... any operation on null yields null.
– Mark Rotteveel
Mar 8 at 17:21