dbTalk Databases Forums  

How to set default for a field bytea ?

comp.databases.postgresql comp.databases.postgresql


Discuss How to set default for a field bytea ? in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
diego
 
Posts: n/a

Default How to set default for a field bytea ? - 06-07-2007 , 02:17 AM







I'd like to set an empty string (not null) in a field bytea as default.

I've tried this:
"txt1" BYTEA DEFAULT ''::bytea

but when i insert a new record the value is always null.Why?

Any help is appreciated.

Thank you.




Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: How to set default for a field bytea ? - 06-08-2007 , 03:30 AM






diego <diego.bonanno@:-)nadteam.net> wrote:
Quote:
I'd like to set an empty string (not null) in a field bytea as default.

I've tried this:
"txt1" BYTEA DEFAULT ''::bytea

but when i insert a new record the value is always null.Why?
Works fine here:

CREATE TABLE a(
id integer NOT NULL PRIMARY KEY,
val bytea DEFAULT ''::bytea);

INSERT INTO a(id) VALUES(1);

SELECT CASE WHEN val IS NULL
THEN 'val is NULL!'
ELSE 'val is not NULL, length is ' || length(val)
END
FROM a WHERE id=1;

case
------------------------------
val is not NULL, length is 0
(1 row)

Could it be that you explicitly enter a NULL value? Then the DEFAULT
would not be effective:

INSERT INTO a VALUES (2, NULL);

SELECT CASE WHEN val IS NULL
THEN 'val is NULL!'
ELSE 'val is not NULL, length is ' || length(val)
END
FROM a WHERE id=2;

case
--------------
val is NULL!
(1 row)

Yours,
Laurenz Albe


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.