I am fairly new to PostgreSQL. I am in the process of converting a MySQL script to postgresql. The mysql script includes a line that reads:
INSERT INTO OVERLAY VALUES
(NULL,LAST_INSERT_ID(),'Grey Standard','basemap',1,'png','y',-1,0,NOW(),NOW()),
(NULL,LAST_INSERT_ID(),'Brown Standard','basemap1',1,'png','y',-1,0,NOW(),NOW());
I am trying to figure out how to get this exact function in the pstgresql db. So far I have this:
CREATE SEQUENCE OVERLAY_SEQ;
CREATE TABLE OVERLAY (
OVERLAY_ID SERIAL DEFAULT nextval('OVERLAY_SEQ'),
PACKAGE_ID SMALLINT NOT NULL,
NAME VARCHAR(64) NOT NULL,
Z_INDEX SMALLINT NOT NULL,
FILE_EXTENSION CHAR(3) NOT NULL,
PRIMARY KEY OVERLAY_ID,
FOREIGN KEY (PACKAGE_ID) REFERENCES PACKAGE PACKAGE_ID)
);
I am trying to use the insert command:
INSERT INTO OVERLAY VALUES
(DEFAULT,currval('OVERLAY_SEQ'),'Grey Standard','basemap',1,'png','y',-1,0,NOW(),NOW()),
(DEFAULT,currval('OVERLAY_SEQ'),'Brown Standard','basemap1',1,'png','y',-1,0,NOW(),NOW())
;
And of course - it's not working. I receive this error message:
psql:create_database.sql:31: ERROR: syntax error at or near "nextval" at character 59
Can anyone help me? I have done a million searches on Google (postgresql currval(), postgresql last_insert_id(), etc.) and still have been unable to come up with a solution. Any help or direction is much appreciated! Thanks, Syl
INSERT INTO OVERLAY VALUES
(NULL,LAST_INSERT_ID(),'Grey Standard','basemap',1,'png','y',-1,0,NOW(),NOW()),
(NULL,LAST_INSERT_ID(),'Brown Standard','basemap1',1,'png','y',-1,0,NOW(),NOW());
I am trying to figure out how to get this exact function in the pstgresql db. So far I have this:
CREATE SEQUENCE OVERLAY_SEQ;
CREATE TABLE OVERLAY (
OVERLAY_ID SERIAL DEFAULT nextval('OVERLAY_SEQ'),
PACKAGE_ID SMALLINT NOT NULL,
NAME VARCHAR(64) NOT NULL,
Z_INDEX SMALLINT NOT NULL,
FILE_EXTENSION CHAR(3) NOT NULL,
PRIMARY KEY OVERLAY_ID,
FOREIGN KEY (PACKAGE_ID) REFERENCES PACKAGE PACKAGE_ID)
);
I am trying to use the insert command:
INSERT INTO OVERLAY VALUES
(DEFAULT,currval('OVERLAY_SEQ'),'Grey Standard','basemap',1,'png','y',-1,0,NOW(),NOW()),
(DEFAULT,currval('OVERLAY_SEQ'),'Brown Standard','basemap1',1,'png','y',-1,0,NOW(),NOW())
;
And of course - it's not working. I receive this error message:
psql:create_database.sql:31: ERROR: syntax error at or near "nextval" at character 59
Can anyone help me? I have done a million searches on Google (postgresql currval(), postgresql last_insert_id(), etc.) and still have been unable to come up with a solution. Any help or direction is much appreciated! Thanks, Syl