Page 1 of 1

Devault values for Row in PGSQL

Posted: Thu Jan 15, 2009 7:09 pm
by swraman
I have a query:

INSERT INTO tr_projects () VALUES ()

which errors. In another thread I found that this will error UNLESS there are default values specified for every column in tr_projects.

There are in fact default values specified; there are 2 (there are 2 columns in tr_projects) and they are:

1) nextval('tr_projects_id_seq'::regclass)
2) 0

But when I run the query, it errors:

Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near ")" LINE 1: INSERT INTO tr_projects () VALUES () ^ in C:\Program Files\BitNami WAPPStack\apache2\htdocs\ascprojects\tracker\pgsql_database.php on line 186

Is there a setting I have to change in PGSQL to make it use the default values automatically? Why doesnt it take the default values specified?

Re: Devault values for Row in PGSQL

Posted: Thu Jan 15, 2009 11:30 pm
by volomike
Try:

INSERT INTO tr_projects VALUES ()

?

Just guessing.

Re: Devault values for Row in PGSQL

Posted: Fri Jan 16, 2009 10:14 am
by swraman
Thanks for the reply :)
I got it resolved, incase anyone else wants to know:

INSERT INTO table_name(column_name, column_name,...) VALUES(DEFAULT, DEFAULT,...)

Re: Devault values for Row in PGSQL

Posted: Fri Jan 16, 2009 10:21 am
by volomike
Really? So using the word DEFAULT without quotes around it -- that works? Surprising.

Re: Devault values for Row in PGSQL

Posted: Fri Jan 16, 2009 10:29 am
by swraman
Yea, I guess its a built in feature to PGSQL.