Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm very new to PostgreSql and still learning the ropes.

I have a really long script for setting up a new copy of my database. It creates functions, runs them, does some inserts and a bunch of other stuff. When I try to run this entire script in the pgAdminIII Query Tool, it throws an error that doesn't seem to make sense.

ERROR:  syntax error at or near ""
LINE 18: /*
         ^

This error gets thrown right after the first alter function owner statement which is after the first create function statement.

If I take each statement out and run them individually then everything runs OK. What gives?

Lines before error:

ALTER FUNCTION table_exists(text) OWNER TO postgres;

Lines at error:

/*
-- Function     : column_exists(text, text)
-- Function output  : true / false
*/

Lines after error:

CREATE FUNCTION column_exists(tablename text, columnname text)
RETURNS boolean AS $$

BEGIN
    RETURN EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = $1 AND column_name = $2);
END;

$$LANGUAGE plpgsql;
share|improve this question
    
Can you paste the lines before and after the error is thrown? –  DrColossos May 10 '11 at 7:25
    
Can you run the script in psql? The syntax all looks good as far as I can see - is it possible there are non-visible characters in the script that are causing the error? –  Jack Douglas May 10 '11 at 10:50
    
Maybe an escaping issue? As already mentioned, the syntax is fine, is there any unsecaped " or ' that may be breaking the script or is a " or ' missing? –  DrColossos May 10 '11 at 14:38
    
Shouldn't be an escaping issue or a non-visible script because if I run the statements individually then it seems to be fine. I even tried removing statements one by one starting from the end but it still hits the same error at the same line. –  Fung May 11 '11 at 3:48
    
When you remove the comment is the error still at the same line or has it moved? Have you tried importing it via the command line? –  DrColossos May 12 '11 at 13:09
show 1 more comment

1 Answer

up vote 1 down vote accepted

Per the comment by Fung:

...it was actually some non-visible character at the beginning of each comment. And the reason the statements still worked when run individually was because I was not running them with the comments

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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