Thread: Advice with an insert query

Advice with an insert query

From
JORGE MALDONADO
Date:
<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">I need to insert records into a table where
onevalue is fixed and 2 values come from a SELECT query, something like the following example:</span><div
style="font-family:arial,sans-serif;font-size:13px"><br/></div><div
style="font-family:arial,sans-serif;font-size:13px">INSERTINTO table1 fld1, fld2, fl3</div><div
style="font-family:arial,sans-serif;font-size:13px">VALUESvalue1, (SELECT fldx, fldy FROM table2)</div><div
style="font-family:arial,sans-serif;font-size:13px"><br/></div><div
style="font-family:arial,sans-serif;font-size:13px">Isthis valid?</div><div
style="font-family:arial,sans-serif;font-size:13px"><br/></div><div
style="font-family:arial,sans-serif;font-size:13px">Respectfully,</div><div
style="font-family:arial,sans-serif;font-size:13px">JorgeMaldonado</div></div> 

Re: Advice with an insert query

From
Andreas Gaab
Date:

INSERT INTO table1 (fld1, fld2, fl3)

VALUES (SELECT value1, fldx, fldy FROM table2);

 

should work,

 

Andreas

 

 

Von: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] Im Auftrag von JORGE MALDONADO
Gesendet: Freitag, 7. Juni 2013 15:59
An: pgsql-sql@postgresql.org
Betreff: [SQL] Advice with an insert query

 

I need to insert records into a table where one value is fixed and 2 values come from a SELECT query, something like the following example:

 

INSERT INTO table1 fld1, fld2, fl3

VALUES value1, (SELECT fldx, fldy FROM table2)

 

Is this valid?

 

Respectfully,

Jorge Maldonado

Re: Advice with an insert query

From
Oliver d'Azevedo Cristina
Date:
Just pass the fixed value for inside the select subquery. 
Do this

INSERT INTO table1 fld1, fld2, fl3
VALUES  (SELECT value1, fldx, fldy FROM table2)

HTH

Best,
Oliver 



Enviado via iPhone

Em 07/06/2013, às 02:58 PM, JORGE MALDONADO <jorgemal1960@gmail.com> escreveu:

I need to insert records into a table where one value is fixed and 2 values come from a SELECT query, something like the following example:

INSERT INTO table1 fld1, fld2, fl3
VALUES value1, (SELECT fldx, fldy FROM table2)

Is this valid?

Respectfully,
Jorge Maldonado

Re: Advice with an insert query

From
Thomas Kellerer
Date:
JORGE MALDONADO, 07.06.2013 15:58:
> I need to insert records into a table where one value is fixed and 2 values come from a SELECT query, something like
thefollowing example:
 
> 
> INSERT INTO table1 fld1, fld2, fl3
> VALUES value1, (SELECT fldx, fldy FROM table2)
> 
> Is this valid?
> 
> Respectfully,
> Jorge Maldonado


INSERT INTO table1 (fld1, fld2, fl3)
SELECT value1, fldx, fldy 
FROM table2