0

Using DBD::Pg im attempting to make an insert statement with binded variables which one of them is a tsrange. I keep getting syntax errors can some one please explain the proper way to do this?

from perl script :

$sth->{'insert'}->execute($hashRef->{'<NUMBER>'}
                                    , $hashRef->{'<FIRSTNAME>'}
                                    , $hashRef->{'<LASTNAME>'}
                                    , $hashRef->{'<DATEIN>'} . ' ' .       $hashRef->{'<TIMEIN>'}
                                    , $hashRef->{'<DATEOUT>'} . ' ' .  $hashRef->{'<TIMEOUT>'}
                                    , $hashRef->{'<JOBCODE>'} 
                                    , $hashRef->{'<JOBCODEDESC>'} 
                                    , $hashRef->{'<COSTCODELEVEL1>'} 
                                    , $hashRef->{'<COSTCODELEVEL2>'} 
                                    , $hashRef->{'<COSTCODELEVEL3>'} 
                                    , $hashRef->{'<DEPARTMENT>'} 
            )or die $DBI::errstr;
    enter code here 

from config file:

sql:
    insert: |-
        insert into etl.timeclock_plus values (
           ? 
         , ? 
         , ?  
         , [ ? , ? ] 
         , ? 
         , ? 
         , ? 
         , ? 
         , ?
         , ? 
        )   
The error : 
syntax error at or near "$4"
3
  • Seems rather unlikely that the error message you show would be generated by that code. Commented Oct 8, 2019 at 15:35
  • Uncaught exception from user code: DBD::Pg::st execute failed: ERROR: syntax error at or near "$4" LINE 5: , '[' $4 ',' $5 ']' ^ at TimeClock.pl line 161. Commented Oct 8, 2019 at 15:47
  • Well, that whole [ ? , ? ] section doesn't look like valid SQL. Commented Oct 8, 2019 at 15:48

1 Answer 1

3

Instead of

[ $1, $2 ]

which is invalid SQL, use a range constructor function:

tstzrange($1, $2, '[)')

There is also tsrange and daterange if you need those data types.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.