검색결과 리스트
글
prepare statements 와 casting
POSTGRESQL
2015. 4. 21. 16:32
상수값으로 잘 실행되는 SQL 구문이 parepare 구문을 이용하면 오류가 발생하는 경우가 있습니다. 이는 바인드변수로 SQL을 실행할때 묵시적형변환이 지원되지 않기 때문입니다.
상수값으로 실행한 결과입니다.
test=# create table test_table(col1 numeric);
CREATE TABLE
test=# insert into test_table values(1);
INSERT 0 1
test=# explain select col1 from test_table where col1 = '1';
QUERY PLAN
-------------------------------------------------------------------------
Seq Scan on test_table (cost=10000000000.00..10000000026.38 rows=7 width=32)
Filter: (col1 = 1::numeric)
(2 rows)
prepare 구문으로 실행한 결과입니다.
test=# prepare foo(varchar) as
test-# select col1 from test_table where col1 = $1;
ERROR: operator does not exist: numeric = character varying
LINE 2: select col1 from test_table where col1 = $1;
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
test=#
prepare 구문상 형변환을 명시하여 실행한 결과입니다.
test=# prepare foo(varchar) as
select col1 from test_table where col1 = $1::numeric;
PREPARE
test=# execute foo('1');
col1
------
1
(1 row)
'POSTGRESQL' 카테고리의 다른 글
| JDBC 테스트 소스 (0) | 2015.06.24 |
|---|---|
| pg_trgm 을 이용한 전후위 like 검색 (0) | 2015.04.21 |
| md5를 이용한 password hash value 구하기 (0) | 2014.11.26 |
| [9.4 beta]ALTER SYSTEM 구문을 이용한 파라메터 변경 (0) | 2014.10.29 |
| table inheritance(상속) (0) | 2014.10.28 |