1

I got a some javascript Dojo code assembling a query from JSON variables and I have been trying to insert a timestamp in it.

This is my test table (schema.mdummy):

  • k and v are varchars
  • n is an integer
  • t is a timestamp

I found out these statements work fine:

INSERT INTO mschema.MDUMMY (k, v) 
VALUES ((SELECT k FROM mschema.MDUMMY WHERE k LIKE 'xp3'), '33');

SELECT TIMESTAMP('1965-07-27', '15:30:00') + 59 SECONDS FROM SYSIBM.SYSDUMMY1;

But this one does not work as expected.

INSERT INTO mschema.MDUMMY (k, n, t) VALUES ( 
 '70', 
 70, 
 (SELECT TIMESTAMP('1965-07-27-15.30.00') + 59 SECONDS FROM SYSIBM.SYSDUMMY1) 
);

Is it some error on the syntax or is it impossible to perform in DB2?

DB Server OS is the latest Fedora server.

closed as unclear what you're asking by mustaccio, ypercubeᵀᴹ, hot2use, Michael Green, McNets Mar 12 '18 at 9:38

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    What does it even mean: "does not work as expected"? What was expected? What happened instead? And why are you using a subselect to calculate the timestamp value? – mustaccio Mar 2 '18 at 15:45
  • 1
    Your statement should work fine, what error did you get? However, there are better ways to do it: insert into mschema.MDUMMY (k, n, t) values ('870',70, TIMESTAMP('1965-07-27-15.30.00') + 59 SECONDS) – Lennart Mar 12 '18 at 13:32
1

Following sequence of statements worked fine in Db2 (for LUW)

create table mschema.MDUMMY (k varchar(10), n int, t timestamp)

INSERT INTO mschema.MDUMMY (k, n, t) VALUES (   '70',   70,   (SELECT
TIMESTAMP('1965-07-27-15.30.00') + 59 SECONDS FROM SYSIBM.SYSDUMMY1) 
);

SELECT * FROM mschema.MDUMMY

I just copied the second statement from your question. This means you made some other mistake running it or you are maybe not running it on Db2 LUW - this is why it is always useful to specify the OS.

  • It is working now. Shout to @Lennart for simplifying the query. – rtrigo Mar 12 '18 at 15:34
  • Ok fine - but also your first try should have worked - this is what I tried to prove. – MichaelTiefenbacher Mar 12 '18 at 17:25
  • Don't really know why, but you're right. My once first solutions works now. – rtrigo Mar 13 '18 at 14:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.