Does not install in PostGres

shunting - May 3, 2009 - 19:37
Project:Teaser Thumbnail
Version:6.x-1.4
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

I changed the schema in the *.install file to read:

case 'pgsql':
$schema['teaserthumbnail'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => t('The {node}.nid associated with the thumbnail.'),
),
'filepath' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => t('Path of the thumbnail source file.'),
),
),
'primary key' => array('nid'),
);

The / 'unsigned' => TRUE line needs to go for the nid column.

#1

hunvreus - May 8, 2009 - 02:18

Hi shunting,

I actually almost never used Postgresql and am not very familiar with it. You are mentioning that by simply removing the "'unsigned' => TRUE" line, the module is able to properly install with such a DB system? Can someone else confirm?

#2

Norbert Poellmann - May 8, 2009 - 19:30

Out of the box there is no type int_unsigned in Postgres. But with CREATE TYPE
and CREATE DOMAIN one
can register a new data type for use in the current database,
see: http://www.postgresql.org/docs/8.3/interactive/sql-createtype.html,
http://www.postgresql.org/docs/8.3/interactive/sql-createdomain.html

In my drupal6 we have such a type, which I think was created during drupal installation.
Look at modules/system/system.install (here with line numbers):
304 function system_install() {
...
312 // Create unsigned types.
313 if (!db_result(db_query("SELECT COUNT(*) FROM pg_constraint WHERE conname = 'int_unsigned_check'"))) {
314 db_query("CREATE DOMAIN int_unsigned integer CHECK (VALUE >= 0)");
315 }
316 if (!db_result(db_query("SELECT COUNT(*) FROM pg_constraint WHERE conname = 'smallint_unsigned_check'"))) {
317 db_query("CREATE DOMAIN smallint_unsigned smallint CHECK (VALUE >= 0)");
318 }
319 if (!db_result(db_query("SELECT COUNT(*) FROM pg_constraint WHERE conname = 'bigint_unsigned_check'"))) {
320 db_query("CREATE DOMAIN bigint_unsigned bigint CHECK (VALUE >= 0)");
321 }

pg_* are postgres system tables. They contain functions, types, field names, etc.
Maybe you missed some step in the installation?

In the SQL Shell psql check:
set search_path to public;
\dT
... (a lot of other types.)...
public | bigint_unsigned |
public | int_unsigned |
public | smallint_unsigned |
...

When listed you can use this types, for example:
create table x ( n int_unsigned ) ;

It checks correctly:

drupal6=# insert into x values (4);
INSERT 0 1
drupal6=# insert into x values (-4);
ERROR: value for domain int_unsigned violates check constraint "int_unsigned_check"

That is the teaserthumbnail table:

drupal6=# \d+ teaserthumbnail
Table "bsn.teaserthumbnail"
Column | Type | Modifiers | Description
----------+------------------------+----------------------------------------+-------------
nid | public.int_unsigned | not null default 0 |
filepath | character varying(255) | not null default ''::character varying |
Indexes:
"teaserthumbnail_pkey" PRIMARY KEY, btree (nid)
Has OIDs: no

 
 

Drupal is a registered trademark of Dries Buytaert.