I am trying to write down a query BUT IT CONTINOUSLY GIVING ME THE ERROR even though everything seems alright. I am using Postgresql as Database.
Error
Th query :
SELECT
re.rad_exam_id
FROM
rad_exam re
INNER JOIN discrete_task_assay dta
ON dta.task_assay_cd = re.task_assay_cd AND dta.default_result_type_cd = (?)
WHERE re.order_id = (?)
ORDER BY re.rad_exam_id
Th error:
Caused by: org.postgresql.util.PSQLException: ERROR: subquery in FROM must have an alias
Related
I want to do a mapping between my postgres DB and the model of the platform on which am working.
the mapper asks me to associate model attributes with DB attributes using SELECT SQL clause.
When writing
SELECT "A"."attribute" or SELECT attribute FROM A;
it generates this error:
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "SELECT"
Position: 8
i tried different select clauses, however, the problem persists !!
Thanks for your help.
What are you trying to achieve? If only selecting the column attribute from the table A then the following should be ok
SELECT attribute FROM A;
The error is stating that or SELECT attribute FROM A; is not a valid statement
I am trying to query from a table within a copy command however, I have continually gotten errors. Here is the example SQL statement.
copy schema.table
from 's3://bucket/folder`
iam_role (select value from roles.iam where key = 'IAMRole');
The inner select statement on its own returns a value however, when I run the above, I get the following error:
SQL Error [500310] [42601]: [Amazon](500310) Invalid operation: syntax error at or near "("
The COPY command, as you must suspect, does not support embedded SQL.
If you want to do something like this, you can, but you'll need a procedure.
I'm trying to copy data from postgres to db2. Just a full table.
I found these instructions and am following them, but they're failing for me on the db2 side.
currently I'm doing:
engine_pstgrs._metadata = MetaData(bind=engine_pstgrs)
engine_pstgrs._metadata.reflect(engine_pstgrs)
table_one = Table('table_one', engine_pstgrs._metadata, schema='prod_schema')
print("Got prod_schema.table_one")
#Create new table
engine_db2._metadata = MetaData(bind=engine_db2)
new_pages = Table('new_pages', engine_db2._metadata, schema='mru')
print("Created new table")
for column in table_one.columns:
print("Column appended to new table")
new_pages.append_column(column.copy())
new_pages.create()
And I'm getting the error:
(ibm_db_dbi.ProgrammingError) ibm_db_dbi::ProgrammingError: Statement Execute Failed: [IBM][CLI Driver][DB2/LINUXX8664] SQL0104N An unexpected token ")" was found following "TABLE MRU.new_pages (". Expected tokens may include: "<table_element_list>". SQLSTATE=42601 SQLCODE=-104 [SQL: '\nCREATE TABLE mru.new_pages (\n)\n\n']
I'm open to trying another way (i.e. Pandas) but I'm not seeing how to do so in a sustainable amount of time (the table is very very large)
Here is a very interesting problem I found.
Here is a snapshot of my table
majorversions Table
Now I try to execute a simple select statement
select * from majorversions mav
where mav.name = "Default-Media"
It throws an error
********** Error **********
ERROR: column "Default-Media" does not exist
SQL state: 42703
Character: 53
It is happening mainly due to the fact that name columnType is Text, if I user client_id in where clause everything works fine.
So how to write a where clause with name as the Column?
Use single quotes for strings.
If it's encased in double quotes it'll think it's a column name and it can't find that column. Thats why you're getting that error.
It should be:
select * from majorversions mav
where mav.name = 'Default-Media'
What it tries to execute in your query is:
select * from majorversions mav where mav.name = mav.Default-Media
Default-Media should be written 'Default-Media' and not "Default-Media"
I have installed DB2 on my local machine and created a table Users with a column Name.
From my portlets I am executing a simple select statement:
Class.forName("com.ibm.db2.jcc.DB2Driver");
String dburl = "jdbc:db2://localhost:50001/Portlets";
conn = DriverManager.getConnection(dburl,"db2admin","password");
String selectTableSQL = "SELECT Name from Users";
statement = conn.createStatement();
ResultSet rs = statement.executeQuery(selectTableSQL);
when i execute this i get the following exception:
com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=DB2ADMIN.USERS, DRIVER=3.62.56.
I dont understand why I am getting this exception. There is nothing much in the stack trace as well.
The SQLCODE in your message is what tells you the actual error message. -204 is the error you are looking for. If you cross-reference the Information Center article about -204, you will see the following message:
name is an undefined name.
And if you look back at your exception, you see name = DB2ADMIN.USERS (the SQLERRMC field).
My guess is that you aren't finding anything because you forgot to append a Schema to your table (the DB2ADMIN part was assumed in the error message because that's your login name).