X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E5EDE9DC80F for ; Sat, 7 Jan 2006 05:48:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50008-02 for ; Sat, 7 Jan 2006 05:48:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from fep04.ttnet.net.tr (mail.ttnet.net.tr [212.175.13.129]) by postgresql.org (Postfix) with ESMTP id B93AF9DC81D for ; Sat, 7 Jan 2006 05:47:47 -0400 (AST) Received: from alamut ([85.102.233.174]) by fep04.ttnet.net.tr with ESMTP id <20060107094450.IHXD1378.fep04.ttnet.net.tr@alamut>; Sat, 7 Jan 2006 11:44:50 +0200 Date: Sat, 7 Jan 2006 11:44:56 +0200 From: Volkan YAZICI To: JiangWei Cc: pgsql-interfaces@postgresql.org Subject: Re: HOWTO pass "default value" to PQexecParams? Message-ID: <20060107094455.GA634@alamut> References: <43BDC4EF.7090408@sduept.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43BDC4EF.7090408@sduept.com> User-Agent: Mutt/1.4.2.1i X-NAI-Spam-Rules: 1 Rules triggered BAYES_10=-0.7 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=2.798 required=5 tests=[DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44, DNS_FROM_RFC_WHOIS=0.879] X-Spam-Score: 2.798 X-Spam-Level: ** X-Archive-Number: 200601/9 X-Sequence-Number: 5925 AFAIK, it's not possible to point the field's default value using a special value in the related array member. Because, you cannot declare any special value in the array: NULL will be treated as NULL and other char values as is. (Recommended.) Why don't you omit id in the target table fields? For instance: sprintf(sql_cmd, "INSERT INTO test (" (id_will_be_default) ? "" : "id, " "name) VALUES (" "..."); PQexecParams(conn, sql_cmd, ...); You can also learn the default value of the related field too. (For more information, run psql with -E parameter and type \d .) Furthermore, it's possible to define a RULE like: ON INSERT IF NEW.id = 0 USE DEFAULT This will assume 0 as a reference to default value. HTH. Regards. On Jan 06 09:16, JiangWei wrote: > Create Table test ( > id int4 not null, > name text default '' > ); > > PQexec (conn, "INSERT INTO test(id, name) VALUES (100,default)" ); // OK. > > PQexecParams (conn, "INSERT INTO test(id, name) VALUES ($1, $2)" ); // > $1=100, $2= ????