I'm trying to run a PostgreSQL query which is:
insert into client (email, name) values ('johndoe#email.com', 'johnDoe');
insert into client_settings (client_id, data) values (currval('client_id_seq'), 0);
insert into client_verify (client_id, dataFields) values (currval('client_id_seq'), json_build_object('data1', ['a1', 'a2'], 'data2', ['b1', 'b2']) );
But I'm getting an error stating SQL Error [42601]: syntax error at or near "[".
The last json object(i.e., the dataFields) when inserted into the DB it should look like:
{"data1": ["a1", "a2"], "data2": ["b1", "b2"]}
Not sure what I am doing wrong. Is there something that I'm missing or a different way to do that?
After good research I found documentation to put 'Array' in front of those like:
json_build_object('data1', Array['a1', 'a2'], 'data2', Array['b1', 'b2'])
Is this what you need :
insert into client_verify (client_id, dataFields)
values (currval('client_id_seq'), json_build_object('data1', 'a1, a2', 'data2', 'b1, b2') );
Please try this:
insert into client_verify (client_id, dataFields)
values (currval('client_id_seq')
, json_build_object('data1', '["a1", "a2"]', 'data2', '["b1", "b2"]'));
Here you can check how you need to add your string:
https://www.freeformatter.com/json-escape.html#ad-output
The UNESCAPE is the option you need
Here is a demo :
DEMO
Related
I have following value:
proc.procSetDebugMode(true);
etl_utils.procSetDebugMode(true);
_analysis.procRunAnalysis(360, <ID_PRCSS_EXCTN>, to_date('<BUSINESS_DATE>', 'YYYY-MM-DD'), '<CONFIG_TYPE>', <G_ROW_COUNT>);
which I need to insert into a specific clob column but unfortunately didn't succeed.
Any tips? The problem seems trivial but still I am unable to resolve it.
insert into JOB
select
1595,
clob(analysis.procSetDebugMode(true); etl_utils.procSetDebugMode(true);analysis.procRunAnalysis(360,<ID_PRCSS_EXCTN>,to_date('<BUSINESS_DATE>','YYYY-MM-DD'), '<CONFIG_TYPE>', <G_ROW_COUNT>);),
INPUT_PARAMS,
UPDATE_STAMP,
UPDAE_USER_LOGIN,
WARNING_TIME,
MAX_EXCTN_TIME,
IS_AWAITING_JOB from JOB where ID = 1585;
SELECT *
FROM Registration
WHERE UserPass = CONVERT(VARBINARY(50),'5avag3',1);
I'm trying to store that password into my database as hash value. Right now the attribute UserPass is in binary and I'm getting this error message:
Implicit conversion from data type varchar to binary is not allowed. Use the CONVERT function to run this query.
Code:
INSERT INTO [dbo].[Registration] ([LoginName], [UserPass], [FirstName],[LastName], [PIC], [DIC])
VALUES ('LogPaul', '', 'Logan', 'Paul', '', '690404-10-5827')
When I try to convert the data type it says I'm unable to convert.
Please help I'm new to SQL, thanks in advance
Just perform the conversion to binary inside the actual INSERT statement:
INSERT INTO [dbo].[Registration] ([LoginName], [UserPass], [FirstName], [LastName],
[PIC], [DIC])
VALUES
('LogPaul', CONVERT(VARBINARY(50),'5avag3',1), 'Logan', 'Paul', '',
'690404-10-5827')
Can't figure out what is wrong with the following SQL query:
INSERT into ALL (name, address, client_id, service_id, service, service_address) values
('Товарищество с ограниченной ответственностью "King Fisher"',
'г.Алматы, ул.Айманова, 155, уг.ул.Жандосова','10','10','Интернет(1024)/10','г.Алматы, ул.Айманова, д.155, уг.Жандосова');
Here is an error output:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALL (name, address, client_id, service_id, service, service_address) values ('' at line 1
Any help would be appreciated)
ALL is a reserved keyword. Because of this, it is necessary to wrap the table name in backticks:
INSERT into `ALL` (name, address, client_id, service_id, service, service_address) values
('Товарищество с ограниченной ответственностью "King Fisher"',
'г.Алматы, ул.Айманова, 155, уг.ул.Жандосова','10','10','Интернет(1024)/10','г.Алматы, ул.Айманова, д.155, уг.Жандосова');
See:
http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
you have not closed the ' quotes, check and try or try using brackets
I'm looking for a way to escape all characters in javascript so i can insert them into a database. But i don't want to use escape() because that's breaking my code.
now getting this error:
[ERROR] invalid SQL statement. Error Domain=com.plausiblelabs.pldatabase Code=3 "An error occured parsing the provided SQL statement." UserInfo=0x6de2b50 {com.plausiblelabs.pldatabase.error.vendor.code=1, NSLocalizedDescription=An error occured parsing the provided SQL statement.
com.plausiblelabs.pldatabase.error.query.string=INSERT INTO vac ( category, title, url, description) VALUES ( '201', ' Adviseur Bankshop', 'someurl', 'description \'t more text.')
You can use parameters in Appcelerator.
DB.db.execute(
"INSERT INTO feeds (title, description) VALUES (?, ?)",
'Good News!', 'A little description'
);
I'm using SQLAlchemy 0.5.8, and seeing this error:
ProgrammingError: (ProgrammingError) can't adapt 'INSERT INTO enumeration_value (id,
key_id, code, name, notes) VALUES (%(id)s, %(key_id)s, %(code)s, %(name)s, %(notes)s)'
{'key_id': 'aac6fc29-4ccd-4fe4-9118-cfbbd04449fe', 'notes': '', 'code': (u'Barnet',),
'id': 'd0540c97-882e-4a5b-bf14-b3ebcfeea051', 'name': (u'Barnet',)}
But a direct SQL insert with the values from the error seems to work just fine:
=> INSERT INTO enumeration_value (id, key_id, code, name, notes)
VALUES ('d0540c97-882e-4a5b-bf14-b3ebcfeea051', 'aac6fc29-4ccd-4fe4-9118-cfbbd04449fe',
'Barnet', 'Barnet', '');
INSERT 0 1
If the direct SQL works OK, how can I start to debug this?
Incidentally, the line that's throwing the error doesn't seem to have an INSERT statement in it at all, so I am a bit confused:
File "----barnet.py", line 117, in load_file
instance = model.Session.query(model.EnumerationValue).filter_by(key=key_barnet_level_2, code=level_2).all()
Do SQLAlchemy filter statements generate INSERT commands, or does this just happen to be the last line before things start to go wrong?
Figured it out - the problem was actually a syntax error a few lines higher up, with a rogue comma:
key_from = code,
Sorry if I wasted anyone's time. Please close the question.