0

I have three tables and I want to insert data into that three tables as per their respective data.

Query:

with acupressure_point_data as (
    insert into acupressure_point(id, url)
        values('LL909', 'ww/33/11')
    returning id as acupressure_point_id
),
acupressure_sub_type as (
    insert into acupressure_point_region_sub_type
        (acupressure_point_id, region_sub_type_id)
        values(acupressure_point_id , '9898')
    returning id as acupressure_sub_type_id
);

But it gives the error as:

"ERROR: syntax error at end of input Position"

I can not understood this. Please help me. Thanks

  • What do you want to return from the SQL statement? – Laurenz Albe Sep 2 at 13:23
1

For PostgerSQL:

with acupressure_point_data as ( -- insert into first table with output
                                 insert into acupressure_point(id, url)
                                 values('LL909', 'ww/33/11')
                                 returning id as acupressure_point_id )
-- insert into second table, use CTE output
insert into acupressure_point_region_sub_type(acupressure_point_id, region_sub_type_id)
SELECT acupressure_point_id , '9898'
FROM acupressure_point_data
-- return id for both tables 
returning acupressure_point_id, id as acupressure_sub_type_id;

MySQL does not allow INSERT in CTE. Use separate queries and LAST_INSERT_ID().

  • Yes '9898' is not from acupressure_point_data. And this is not literal, i stored it as variable in the python script and that variable i send in the query as '9898'. – Suhel Sep 2 at 13:46
  • @Suhel Well, send it into your query as 3rd parameter (1st and 2nd are 'LL909' and 'ww/33/11' respectively). – Akina Sep 2 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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