[development] A little pgsql help

Piotr Krukowiecki piotr at mallorn.ii.uj.edu.pl
Mon Mar 13 19:04:10 UTC 2006


On Mon, Mar 13, 2006 at 12:16:05PM -0500, Daniel Convissor wrote:
> On Thu, Mar 09, 2006 at 04:09:37PM +0100, Piotr Krukowiecki wrote:
> > 
> > I've also added default values because iirc mysql will insert '' if
> > there is no default and no value is provided.
> 
> If a default is not specified, the query will fail if the given column is 
> not directly specified by the insert query.  

mysql 4.1.11 - either the default is allways added (i.e. you can't specify 
a column without a default) or if there is no default, the empty string
is inserted:


mysql> create table foobar (a varchar(10) NOT NULL, b int NOT NULL);
Query OK, 0 rows affected (0.02 sec)

mysql> describe foobar;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| a     | varchar(10) |      |     |         |       |
| b     | int(11)     |      |     | 0       |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> insert into foobar(b) values(10);
Query OK, 1 row affected (0.00 sec)

mysql> select concat('x', a, 'x'), concat('x', b, 'x') FROM foobar;
+---------------------+---------------------+
| concat('x', a, 'x') | concat('x', b, 'x') |
+---------------------+---------------------+
| xx                  | x10x                |
+---------------------+---------------------+
1 row in set (0.00 sec)

mysql> select * FROM foobar WHERE a IS NULL;
Empty set (0.02 sec)



-- 
Piotrek
irc: #debian.pl
Mors Drosophilis melanogastribus!


More information about the development mailing list