Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres: Inserting rows into table with foreign key

Tags:

sql

postgresql

I have a table with a foreign key type which links to table wp_types. Whenever I try and insert a row into that table I get the error:

ERROR:  permission denied for schema base
LINE 1: SELECT 1 FROM ONLY "base"."wp_types" x WHERE "id" OPERATOR(p...
                       ^
QUERY:  SELECT 1 FROM ONLY "base"."wp_types" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR SHARE OF x

The query is being executed as postgres. Also I do not understand what this query is trying to do, it is clearly linked with checking the foreign key constraints but I don't understand how.

like image 572
Russell Fulton Avatar asked Oct 21 '25 09:10

Russell Fulton


1 Answers

From postgresql docs:

If ONLY is specified, only that table is scanned. If ONLY is not specified, the table and all its descendant tables (if any) are scanned.

As you mentioned error is connected with checking foreign keys. When ONLY is specified postgres can not check them and it may cause an error.

like image 127
Jerzy Pawlikowski Avatar answered Oct 23 '25 22:10

Jerzy Pawlikowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!