1
psql -d mydb -U me -h localhost -f db_log.sql -v db_user_string='Me' -v version="1.7.3"

into the script

begin;

create table db_log (
    db_owner varchar(255) not null, 
    db_user varchar(255) not null, 
    version varchar(255) not null, 
    created timestamp, 
    id serial primary key
);

insert into db_log (db_owner, db_user, version, created) 
    VALUES (current_user, :db_user_string, :version, current_timestamp);

commit;

gives...

psql:db_log.sql:10: ERROR:  syntax error at or near ".3"

Any ideas?

I am using 9.3.0

1
  • 1
    Why do you use varchar(255)? Why not varchar(256), or, even better, unlimited varchar ortext? Mar 3, 2015 at 15:29

1 Answer 1

2

Try an extra layer of quotes around your variables:

psql -d mydb -U me -h localhost -f db_log.sql -v db_user_string="'Me'" -v version="'1.7.3'"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.