8000 Adding an example of how to insert array data using a prepared statem… · danielcode/ruby-pg@8619ef0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8619ef0

Browse files
committed
Adding an example of how to insert array data using a prepared statement (issue #145)
1 parent f7d556d commit 8619ef0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sample/array_insert.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'pg'
4+
5+
c = PG.connect( dbname: 'test' )
6+
7+
# this one works:
8+
c.exec( "DROP TABLE IF EXISTS foo" )
9+
c.exec( "CREATE TABLE foo (strings character varying[]);" )
10+
11+
# But using a prepared statement works:
12+
c.set_error_verbosity( PG::PQERRORS_VERBOSE )
13+
c.prepare( 'stmt', "INSERT INTO foo VALUES ($1);" )
14+
15+
# This won't work
16+
#c.exec_prepared( 'stmt', ["ARRAY['this','that']"] )
17+
18+
# but this will:
19+
c.exec_prepared( 'stmt', ["{'this','that'}"] )
20+

0 commit comments

Comments
 (0)
0