dbTalk Databases Forums  

Determine length of bitfield

comp.databases.postgresql comp.databases.postgresql


Discuss Determine length of bitfield in the comp.databases.postgresql forum.



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

Default Determine length of bitfield - 06-12-2008 , 08:59 AM






Hello list,

I'm currently trying to insert data into a table which contains a

bit(32)

field. However, the "32" bits should be kept variable, that means I do
not want to code something that relies on the field length to be 32, it
might well be 48 or 64. So what I'm trying to do is the following

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS bit(32)));

This works. However, the bit(32) is explicit. What I'd like is something
like

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS TYPEOF(bitfield)));

How is that possible when using Postgres?

Thanks a lot,
Johannes

--
"Wer etwas kritisiert muss es noch lange nicht selber besser können. Es
reicht zu wissen, daß andere es besser können und andere es auch
besser machen um einen Vergleich zu bringen." - Wolfgang Gerber
in de.sci.electronics <47fa8447$0$11545$9b622d9e (AT) news (DOT) freenet.de>

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

Default Re: Determine length of bitfield - 06-13-2008 , 05:22 AM






Johannes Bauer <dfnsonfsduifb (AT) gmx (DOT) de> wrote:
Quote:
I'm currently trying to insert data into a table which contains a

bit(32)

field. However, the "32" bits should be kept variable, that means I do
not want to code something that relies on the field length to be 32, it
might well be 48 or 64. So what I'm trying to do is the following

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS bit(32)));

This works. However, the bit(32) is explicit. What I'd like is something
like

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS TYPEOF(bitfield)));

How is that possible when using Postgres?
As far as I know, no.

What do you want to achieve, I mean, what is your goal?
Maybe there is a different way to do it.

Yours,
Laurenz Albe


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

Default Re: Determine length of bitfield - 06-13-2008 , 05:22 AM



Johannes Bauer <dfnsonfsduifb (AT) gmx (DOT) de> wrote:
Quote:
I'm currently trying to insert data into a table which contains a

bit(32)

field. However, the "32" bits should be kept variable, that means I do
not want to code something that relies on the field length to be 32, it
might well be 48 or 64. So what I'm trying to do is the following

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS bit(32)));

This works. However, the bit(32) is explicit. What I'd like is something
like

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS TYPEOF(bitfield)));

How is that possible when using Postgres?
As far as I know, no.

What do you want to achieve, I mean, what is your goal?
Maybe there is a different way to do it.

Yours,
Laurenz Albe


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

Default Re: Determine length of bitfield - 06-13-2008 , 05:22 AM



Johannes Bauer <dfnsonfsduifb (AT) gmx (DOT) de> wrote:
Quote:
I'm currently trying to insert data into a table which contains a

bit(32)

field. However, the "32" bits should be kept variable, that means I do
not want to code something that relies on the field length to be 32, it
might well be 48 or 64. So what I'm trying to do is the following

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS bit(32)));

This works. However, the bit(32) is explicit. What I'd like is something
like

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS TYPEOF(bitfield)));

How is that possible when using Postgres?
As far as I know, no.

What do you want to achieve, I mean, what is your goal?
Maybe there is a different way to do it.

Yours,
Laurenz Albe


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

Default Re: Determine length of bitfield - 06-13-2008 , 05:22 AM



Johannes Bauer <dfnsonfsduifb (AT) gmx (DOT) de> wrote:
Quote:
I'm currently trying to insert data into a table which contains a

bit(32)

field. However, the "32" bits should be kept variable, that means I do
not want to code something that relies on the field length to be 32, it
might well be 48 or 64. So what I'm trying to do is the following

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS bit(32)));

This works. However, the bit(32) is explicit. What I'd like is something
like

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS TYPEOF(bitfield)));

How is that possible when using Postgres?
As far as I know, no.

What do you want to achieve, I mean, what is your goal?
Maybe there is a different way to do it.

Yours,
Laurenz Albe


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

Default Re: Determine length of bitfield - 06-13-2008 , 05:22 AM



Johannes Bauer <dfnsonfsduifb (AT) gmx (DOT) de> wrote:
Quote:
I'm currently trying to insert data into a table which contains a

bit(32)

field. However, the "32" bits should be kept variable, that means I do
not want to code something that relies on the field length to be 32, it
might well be 48 or 64. So what I'm trying to do is the following

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS bit(32)));

This works. However, the bit(32) is explicit. What I'd like is something
like

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS TYPEOF(bitfield)));

How is that possible when using Postgres?
As far as I know, no.

What do you want to achieve, I mean, what is your goal?
Maybe there is a different way to do it.

Yours,
Laurenz Albe


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

Default Re: Determine length of bitfield - 06-13-2008 , 05:22 AM



Johannes Bauer <dfnsonfsduifb (AT) gmx (DOT) de> wrote:
Quote:
I'm currently trying to insert data into a table which contains a

bit(32)

field. However, the "32" bits should be kept variable, that means I do
not want to code something that relies on the field length to be 32, it
might well be 48 or 64. So what I'm trying to do is the following

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS bit(32)));

This works. However, the bit(32) is explicit. What I'd like is something
like

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS TYPEOF(bitfield)));

How is that possible when using Postgres?
As far as I know, no.

What do you want to achieve, I mean, what is your goal?
Maybe there is a different way to do it.

Yours,
Laurenz Albe


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

Default Re: Determine length of bitfield - 06-13-2008 , 05:22 AM



Johannes Bauer <dfnsonfsduifb (AT) gmx (DOT) de> wrote:
Quote:
I'm currently trying to insert data into a table which contains a

bit(32)

field. However, the "32" bits should be kept variable, that means I do
not want to code something that relies on the field length to be 32, it
might well be 48 or 64. So what I'm trying to do is the following

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS bit(32)));

This works. However, the bit(32) is explicit. What I'd like is something
like

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS TYPEOF(bitfield)));

How is that possible when using Postgres?
As far as I know, no.

What do you want to achieve, I mean, what is your goal?
Maybe there is a different way to do it.

Yours,
Laurenz Albe


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

Default Re: Determine length of bitfield - 06-13-2008 , 05:22 AM



Johannes Bauer <dfnsonfsduifb (AT) gmx (DOT) de> wrote:
Quote:
I'm currently trying to insert data into a table which contains a

bit(32)

field. However, the "32" bits should be kept variable, that means I do
not want to code something that relies on the field length to be 32, it
might well be 48 or 64. So what I'm trying to do is the following

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS bit(32)));

This works. However, the bit(32) is explicit. What I'd like is something
like

INSERT INTO mytable (bitfield) VALUES (CAST(0 AS TYPEOF(bitfield)));

How is that possible when using Postgres?
As far as I know, no.

What do you want to achieve, I mean, what is your goal?
Maybe there is a different way to do it.

Yours,
Laurenz Albe


Reply With Quote
  #10  
Old   
Johannes Bauer
 
Posts: n/a

Default Re: Determine length of bitfield - 06-13-2008 , 08:16 AM



Laurenz Albe schrieb:

Quote:
What do you want to achieve, I mean, what is your goal?
Maybe there is a different way to do it.
I'm trying to insert a "0" bitvector into the table no matter how the
table structure is. This means if the table structure is bit(8) I want
to insert B'00000000', but if the table should be bit(4) I'd like to
insert B'0000' - all of this without having to rely on the exact length
or the need to check this in advance.

Regards,
Johannes

--
"Wer etwas kritisiert muss es noch lange nicht selber besser können. Es
reicht zu wissen, daß andere es besser können und andere es auch
besser machen um einen Vergleich zu bringen." - Wolfgang Gerber
in de.sci.electronics <47fa8447$0$11545$9b622d9e (AT) news (DOT) freenet.de>


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.