#native_company# #native_desc#
#native_cta#

get insert ID from PostgreSQL

By NIkolay Mihaylov
on April 17, 2002

Version: .1

Type: Sample Code (HOWTO)

Category: Databases

License: GNU General Public License

Description: Mysql has it, why doesn’t PG? This lets you do the same thing.

<? /*
This is not a code exactly, code it yourself:

create sequence x_seq;

create table x(
    a int4 not null default nextval('x_seq'),
    b char(10)
);

create unique index x_pk on x(a);

-------------
in php.

first execute a query and get result:

$x=value_of_this("select nextval('x_seq') as x"); //will not work if you copy paste it

then exec full sql:

insert into x values($x, 'somedata');

use $x ...

*/ ?>