Answer the question
In order to leave comments, you need to log in
How to copy fields from one table to another?
PostgreSQL 10. There are two tables connected with each other. The recording table actually has other columns, otherwise it may seem that the tables are the same.
create table video (
"id" serial primary key,
"videoId" varchar(25) not null,
"recordingId" serial REFERENCES recording (id),
"default" varchar(100),
"medium" varchar(100),
"high" varchar(100),
unique ("videoId", "recordingId")
);
create table recording (
"id" serial primary key,
"videoId" varchar(15) not null,
"default" varchar(60),
"medium" varchar(60),
"high" varchar(60)
);
UPDATE recording
SET recording."videoId" = video."videoId"
SET recording.default = video.default
SET recording.medium = video.medium
SET recording.high = video.high
FROM video
WHERE recording.id = video."recordingId"
Answer the question
In order to leave comments, you need to log in
Try this query:
UPDATE recording
SET recording.videoId. = video.videoId
SET recording.default = video.default
SET recording.medium = video.medium
SET recording.high = video.high
FROM video
JOIN recording
ON recording.id = video.recordingId
You can make a test query before running update, like this :
Select
recording.videoId, video.videoId
recording.default, video.default
recording.medium, video.medium
recording.high, video.high
FROM video
JOIN recording
ON recording.id = video.recordingId
The query will show which records were selected for the update.
About varchar: varchar stores as many characters as actually transferred, and char as many as specified in the field description.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question