marți, 29 martie 2016

PostgreSQL: currval: Return the value of the most recently id generated

--Create table
create table geoipv4.geoipsv4def(
 -- use BIGSERIAL to have an auto-incremented key
 geoipsv4id BIGSERIAL,
 ipStart text, ipEnd text,
 ipNumberStart decimal,ipNumberEnd decimal,
 countryCode text,
 countryName text);

-- Insert a row into the newly created table
INSERT INTO geoipv4.geoipsv4def
   (ipStart,ipEnd, ipNumberStart, ipNumberEnd,
   ('','','701431808','701439999','CI','Cote D''Ivoire');

-- Select the last generated id
SELECT currval('geoipv4.geoipsv4def_geoipsv4id_seq');

-- Select the last inserted row
Select * from geoipv4.geoipsv4def
where geoipsv4id in
  (SELECT currval('geoipv4.geoipsv4def_geoipsv4id_seq'));

Niciun comentariu:

Trimiteți un comentariu