how to use constants in SQL CREATE TABLE?

Posted by kchiu on Stack Overflow See other posts from Stack Overflow or by kchiu
Published on 2011-01-01T00:48:39Z Indexed on 2011/01/01 0:53 UTC
Read the original article Hit count: 221

Filed under:
|

Hi,

I have 3 SQL tables, defined as follows:

 CREATE TABLE organs(
    abbreviation   VARCHAR(16),
    -- ... other stuff
 );
 CREATE TABLE blocks(
    abbreviation   VARCHAR(16),
    -- ... other stuff
 );
 CREATE TABLE slides(
    title          VARCHAR(16),
    -- ... other stuff
 );

The 3 fields above all use VARCHAR(16) because they're related and have the same length restriction.

Is there a (preferably portable) way to put '16' into a constant / variable and reference that instead in CREATE TABLE? eg. something like this would be nice:

 CREATE TABLE slides(
    title          VARCHAR(MAX_TITLE_LENGTH),
    -- ... other stuff
 );

I'm using PostgreSQL 8.4.

thanks a lot, and Happy New Year!

cheers.

© Stack Overflow or respective owner

Related posts about sql

Related posts about postgresql