0

I have a table Ty contains:

  a integer NOT NULL,
  b text,
  c text,
  d text,
  e text

I'm trying to do insrert statment as follows:

insert into Ty (b,c,d,e) values
                ('hello','world',select current_date,select name from users where userid=4)

But it doesn't work. It says:

ERROR: syntax error at or near "select"

All guides I read says that I can do SQL statement in Insert as long as they return just one value. So why it doesn't work?

1
  • You need parentheses around the subqueries Commented Jul 15, 2015 at 13:03

3 Answers 3

2
insert into Ty (b,c,d,e) 
select 'hello','world',current_date,name from users 
where userid=4
Sign up to request clarification or add additional context in comments.

3 Comments

The keyword values causes same error. @Paul answer works
I noticed extrac brace and already removed it. See my edited reply
Still won't work; the values keyword shouldn't be there
1
insert into Ty (b,c,d,e)
SELECT 'hello','world',current_date, name from users where userid=4

Comments

0

a second way to do it is to add ( ) around the SELECT as shown in the next example:

test=# SELECT (SELECT 1);
 ?column? 
----------
        1
(1 row)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.