I have some issue regarding update column of a table in PostgreSQL
My PostgreSQL version is 9.3
Eg:
In below example jifileresource is the table and column name is DATA
public is the schema
bytea_import is the function to retrieve the content of a file
UPDATE jifileresource
SET DATA=(SELECT public.bytea_import('D:/BOB_XML/BOB.xml')
WHERE ID=2235;
i am getting error like this:
ERROR: syntax error at end of input
LINE 4: WHERE ID=2235
^
********** Error **********
ERROR: syntax error at end of input
SQL state: 42601
You are opening two parentheses and closing only one.
UPDATE jifileresource
SET DATA = (SELECT public.bytea_import('D:/BOB_XML/BOB.xml')) <-- here a ")" was missing
WHERE ID=2235;
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.
Having a problem with this, trying to add a column which returns the year from a date column in postgresql 10: This is my SQL
ALTER TABLE stats ADD COLUMN year_ integer GENERATED ALWAYS AS (date_part('year', date)) STORED;
However, this returns a syntax error in the SQL window. I have looked up the online documentation and have no idea what is going wrong, also tried with the EXTRACT function and I keep on getting the same error of the sort
ERROR: syntax error at or near "("
LINE 1: ...tats ADD COLUMN year_ integer GENERATED ALWAYS AS (date_part...
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 am trying to use PostgreSQL's currval function to return the last inserted row id of a table called Concept. Concept has a serial primary key called cid and there was an automatically generated Sequence called Concept_cid_seq.
I try the following statement and get an error:
SELECT currval("Concept_cid_seq");
ERROR: column "Concept_cid_seq" does not exist
LINE 1: SELECT currval("Concept_cid_seq");
^
********** Error **********
ERROR: column "Concept_cid_seq" does not exist
SQL state: 42703
Character: 16
But when I run the query :
SELECT * from "Concept_cid_seq";
I get a table with one row (as I'd expect) showing columns like last_value, start_value, etc...
What am I missing here? Am I passing the wrong information to currval? Why does it say the 'column does not exist?'
It turns out that this was an issue with capitalization and quotes. Because I wanted to preserve the capitalization of the relation name I needed to use both single and double quotes in order to pass the correct relation name to currval.
I changed the query to SELECT currval('"Concept_cid_seq"'); (note the outer single quotes) and it worked correctly.