1"use strict";(globalThis.webpackChunkkysely_site=globalThis.webpackChunkkysely_site||[]).push([[6981],{2917(e,s,t){t.r(s),t.d(s,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>o,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"examples/insert/insert-subquery","title":"Insert subquery","description":"You can create an INSERT INTO SELECT FROM query using the expression method.","source":"@site/docs/examples/insert/0050-insert-subquery.mdx","sourceDirName":"examples/insert","slug":"/examples/insert/insert-subquery","permalink":"/docs/examples/insert/insert-subquery","draft":false,"unlisted":false,"editUrl":"https://github.com/kysely-org/kysely/tree/master/site/docs/examples/insert/0050-insert-subquery.mdx","tags":[],"version":"current","sidebarPosition":50,"frontMatter":{"title":"Insert subquery"},"sidebar":"tutorialSidebar","previous":{"title":"Complex values","permalink":"/docs/examples/insert/complex-values"},"next":{"title":"UPDATE","permalink":"/docs/category/update"}}');var r=t(1058),i=t(4801),l=t(2360);const o={title:"Insert subquery"},a="Insert subquery",c={},u=[];function d(e){const s={a:"a",admonition:"admonition",code:"code",h1:"h1",header:"header",li:"li",p:"p",ul:"ul",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.header,{children:(0,r.jsx)(s.h1,{id:"insert-subquery",children:"Insert subquery"})}),"\n",(0,r.jsxs)(s.p,{children:["You can create an ",(0,r.jsx)(s.code,{children:"INSERT INTO SELECT FROM"})," query using the ",(0,r.jsx)(s.code,{children:"expression"})," method.\nThis API doesn't follow our WYSIWYG principles and might be a bit difficult to\nremember. The reasons for this design stem from implementation difficulties."]}),"\n","\n","\n",(0,r.jsx)("div",{style:{marginBottom:"1em"},children:(0,r.jsx)(l.Q,{code:"const result = await db.insertInto('person')\n .columns(['first_name', 'last_name', 'age'])\n .expression((eb) => eb\n .selectFrom('pet')\n .select((eb) => [\n 'pet.name',\n eb.val('Petson').as('last_name'),\n eb.lit(7).as('age'),\n ])\n )\n .execute()"})}),"\n",(0,r.jsxs)(s.admonition,{title:"More examples",type:"info",children:[(0,r.jsxs)(s.p,{children:["The API documentation is packed with examples. The API docs are hosted ",(0,r.jsx)(s.a,{href:"https://kysely-org.github.io/kysely-apidoc/",children:"here"}),",\nbut you can access the same documentation by hovering over functions/methods/classes in your IDE. The examples are always\njust one hover away!"]}),(0,r.jsx)(s.p,{children:"For example, check out these sections:"}),(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsx)(s.li,{children:(0,r.jsx)(s.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/InsertQueryBuilder.html#values",children:"values method"})}),"\n",(0,r.jsx)(s.li,{children:(0,r.jsx)(s.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/InsertQueryBuilder.html#onConflict",children:"onConflict method"})}),"\n",(0,r.jsx)(s.li,{children:(0,r.jsx)(s.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/InsertQueryBuilder.html#returning",children:"returning method"})}),"\n",(0,r.jsx)(s.li,{children:(0,r.jsx)(s.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/Kysely.html#insertInto",children:"insertInto method"})}),"\n"]})]})]})}function h(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.