0

Do null columns consume the same space on disk as when transferred over the network to a client?

How wide, in bytes, is a null column in a table in a PostgreSQL database?

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
Derek Mahar
  • 27,608
  • 43
  • 124
  • 174

1 Answers1

1

Missed your second question at first:

Most clients communicate with the db server via text. Depending on the format that's either the string NULL or nothing (for instance in COPY output or the text format of pg_dump) instead of a value.
This is completely different from how NULL values are stored inside the database. (See added links.)

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • Do you happen to know if the PostgreSQL JDBC driver in particular communicates with the server in plain text? – Derek Mahar Apr 10 '13 at 20:25
  • 2
    http://www.postgresql.org/docs/9.2/static/protocol-message-formats.html describes the messages in the PostgreSQL wire protocol. Message `DataRow` explains that a `Null` column is assigned size -1 and has zero data bytes. – Derek Mahar Apr 10 '13 at 20:34
  • 2
    @DerekMahar Yes, PgJDBC uses the text protocol. It has some support for the binary protocol but I don't recommend using it for anything except transferring lots of `bytea` values. – Craig Ringer Apr 10 '13 at 23:43