SQLAlchemy ProgrammingError - how to debug? - sql

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.

Related

Error at or near square brackets - Postgres

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

Error: "Column name or number of supplied values does not match table definition" Despite column match

I was hoping someone could point me in the right direction for troubleshooting.
I work for a small company and we are building a new application. I have the insert statement below (with selected static values for testing) that was working until this morning when we started getting error messages from it (we changed nothing about this table).
INSERT INTO t_el_powertrain
(
[pt_id]
,[el_id]
,[segment_id]
,[continuous_hp]
,[intermittent_hp]
,[torque]
,[torque_rpm]
,[eop]
,[checked_out]
,[create_date]
,[created_by]
,[update_date]
,[updated_by]
,[captive]
)
SELECT 1, --pt_id
100000, --el_id
5 , --segment_id
5.00, --continuous_hp
5.00, --intermittent_hp
5.00, --torque
5, --torque_rpm
5, --eop
0, --checked_out
GetDate(), --create_date
5 , --created_by
GetDate(), --update_date
5, --updated_by
10
Error message:
Here is a screenshot of the table structure (I refreshed the connection right before)
It seems pretty clear to me that there should be no issues with the insert statement below. Does anyone have any idea why I might be getting an error here?
Thanks for the help!
EDIT: added picture of the error message
UPDATE:
Thanks to a quick response from Martin Smith, I realized that I totally overlooked what DB object was throwing the error.
I forgot to update our history mirror table when I added a column a while back.
Solved. Thanks again.

Error parsing the query token line error

I am trying to enter fictional values into a table I created with columns. I am getting this error:
Major Error 0x80040E14, Minor Error 25501
insert into employees (`first`, `last`, `title`, `age`, `salary`)
values (`Jonie`, `Weber`, `Secretary`, `28`, `19500`))
There was an error parsing the query. [ Token line number = 2,Token line offset = 2,Token in error = ` ]
I have entered:
insert into employees (`first`, `last`, `title`, `age`, `salary`)
values (`Jonie`, `Weber`, `Secretary`, `28`, `19500`));
What am I doing incorrectly?
You need to put quotes around strings, not backticks:
insert into employees (first, last, title, age, salary)
values ('Jonie', 'Weber', 'Secretary', 28, 19500)
And you have a ) too much at the end.

Derby DB Insert Error SQL state 21000

I am attempting to insert data into a table in my database. I am using an Oracle Apache Derby DB. I have the following code-
Insert into P2K_DBA.ODS_CNTRL
(ODS_LOAD_ID, ODS_STATUS, USR_WWID, USR_FIRST_NM,
USR_LAST_NM, USR_DISPLAY_NM, USR_NT_ID,TOT_AMT,
TOT_RCD_CNT, TOT_QTY, LAST_UPD_DT, ODS_ADJ_TYP,
ODS_ADJ_DESC, APRV_WWID, APRV_FIRST_NM,APRV_LAST_NM,
APRV_DISPLAY_NM, APRV_NT_ID, APRV_DT
)
values
(6,'avail','64300339', 'Travis',
'Taylor', 'TT', '3339', 33,
15, 40, '7/10/2012', 'test',
'test', '64300337', 'Travis',
'Taylor', 'TT', '3339', '2/06/2013');
I ran this SQL command and received the following error-
"Error code -1, SQL state 21000: Scalar subquery is only allowed to return a single row.
Line 1, column 1"
I have ran this code successfully a few days ago. On top of that I have tried to manually enter in data in this table (using NetBeans) and have it auto generate the code, which resulted in the same error.
What is causing this error and how can I solve/bypass it?
One way in which you could run into this would be to do something like
CREATE FUNCTION F(...) ...
F((SELECT COL FROM T))
But you could instead write
... (SELECT F(COL) FROM T) provided the new context permits a subquery, that is.

Oracle error - ORA-00936: missing expression

I'm getting an error message of "ORA-00936: missing expression" at the very start of line 2 at SELECT. I've looked over the data a countless number of times but can't seem to notice where i'm going wrong. I have a feeling it will be something extremely obvious! Any help would be great
Insert into EmployeeTable values
SELECT Name('Mrs','Alison','Smith'),
Address('23 Dart Grove', 'Edinburgh', 'EH10 5TT'),
Phone('01312125555', '07705623443','07907812345'),
'N1001',
ref(b),
'null',
'101',
'Head',
'50000',
'01-FEB-92'
from branchtable b
where b.bID = '901';
Remove the VALUES:
Insert into EmployeeTable
SELECT ...
But I fear that this might not be the only issue...