There’s no need to do this via raw SQL.
Make use of the WordPress core functions get_post_meta
and update_post_meta
.
Use them like so:
$existing = get_post_meta( $post_id, 'existingkey', true );
if ( ! empty( $existing ) ) {
update_post_meta( $post_id, 'newkey', 'newvalue' );
}
Done.